#include <bits/stdc++.h>
using namespace std;
long long solve(long long x, long long len) {
  set<long long> taken;
  long long cnt = len;
  long long pp = 10;
  for (long long i = 1; i < cnt; i++) {
    long long k = x % pp;
    taken.insert(solve(k, i));
    pp = pp * 10;
  }
  long long ret = x;
  long long ad = pp;
  while (ret < 1989 || taken.find(ret) != taken.end()) {
    ret += ad;
  }
  return ret;
}
long long stringToll(string ss) {
  long long ret = 0;
  for (long long i = 4; i < ss.size(); i++) {
    ret = ret * 10 + (long long)(ss[i] - '0');
  }
  return ret;
}
int main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    string st;
    cin >> st;
    long long y = stringToll(st);
    long long len = st.size() - 4;
    cout << solve(y, len) << endl;
  }
  return 0;
}
