#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline string get() {
  char ch[1000010];
  scanf("%s", ch);
  return ch;
}
const int MAX_LG = 21;
const long long maxn = 20;
const long long base = 29;
const long long mod = 1e9 + 7;
const long long INF = 1e9 + 100;
long long pw[maxn];
long long suffix[maxn];
inline long long bigger(long long lim, string suf) {
  long long sz = suf.size();
  long long num = atoi(suf.c_str());
  suffix[sz] = num;
  for (long long i = sz + 1; i <= 15; i++) {
    suffix[i] = suffix[i - 1] + pw[i - 1] * 9;
  }
  long long ret = 0;
  for (long long i = 15; i >= sz + 1; i--) {
    for (long long dig = 0; dig <= 9; dig++) {
      long long value = pw[i - 1] * dig + suffix[i - 1];
      if (value + ret > lim) {
        ret += pw[i - 1] * dig;
        break;
      }
    }
  }
  ret += num;
  return ret;
}
inline long long solve(string &s) {
  long long lim = 1988;
  for (long long i = (long long)s.size() - 1; i >= 0; i--)
    lim = bigger(lim, s.substr(i, s.size()));
  return lim;
}
int32_t main() {
  pw[0] = 1;
  for (long long i = 1; i <= 16; i++) pw[i] = 10 * pw[i - 1];
  long long n = in();
  while (n--) {
    string s = get().substr(4, 15);
    cout << solve(s) << "\n";
  }
}
