#include <bits/stdc++.h>
using namespace std;
int cond = (long long)1;
map<string, long long> dp;
void solve() {
  string buf;
  cin >> buf;
  string s = string(buf.c_str() + 4);
  int n = s.size();
  long long p10 = 1;
  long long atLeast = 1989 - 1;
  {
    if (cond > 0) {
      cond--;
      for (auto xxx = (0); xxx < (1); ++xxx)
        cerr << 32 << " "
             << "buf << \" \" << s"
             << " " << buf << " " << s << endl;
      cerr.flush();
    }
  };
  for (auto i = (n - 1); i >= (0); --i) {
    p10 *= 10;
    int cur;
    sscanf(s.c_str() + i, "%d", &cur);
    long long x = cur;
    for (; x <= atLeast; x += p10) {
    }
    atLeast = x;
  }
  cout << atLeast << endl;
}
const int multi = 1;
int main(int argc, char** argv) {
  ios::sync_with_stdio(false);
  cond = argc >= 2 && argv[1][0] == 'q' ? 1 << 30 : 0;
  int t;
  if (multi)
    cin >> t;
  else
    t = 1;
  for (auto i = (1); i <= (t); ++i) {
    if (cond) cerr << 54 << " " << i << endl;
    solve();
    fflush(stdout);
    cerr.flush();
  }
  return 0;
}
