#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T b, T p, T m) {
  T ret;
  if (p == 0) return 1;
  if (p & 1) {
    ret = (bigmod(b, p / 2, m) % m);
    return ((b % m) * ret * ret) % m;
  } else {
    ret = (bigmod(b, p / 2, m) % m);
    return (ret * ret) % m;
  }
}
int dx4[] = {1, -1, 0, 0};
int dy4[] = {0, 0, 1, -1};
int dx6[] = {0, 0, 1, -1, 0, 0};
int dy6[] = {1, -1, 0, 0, 0, 0};
int dz6[] = {0, 0, 0, 0, 1, -1};
int dx8[] = {1, -1, 0, 0, -1, 1, -1, 1};
int dy8[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dkx8[] = {-1, 1, -1, 1, -2, -2, 2, 2};
int dky8[] = {2, 2, -2, -2, 1, -1, 1, -1};
int tc = 1;
const double eps = 1e-9;
const double pi = acos(-1.0);
const long long int mx = 1e5;
const long long int mod = 1e9 + 7;
vector<long long> year[15];
void gen(void) {
  long long i, a, b, c;
  a = 1989;
  c = 9;
  for (i = 0; i < 9; i++) {
    b = a + c;
    year[i + 1].push_back(a);
    year[i + 1].push_back(b);
    a = b + 1;
    c = c * 10 + 9;
  }
}
long long _pow(long long x, long long n) {
  long long i, ans = 1;
  for (i = 1; i <= n; i++) ans *= x;
  return ans;
}
int main() {
  long long i, n, x, t;
  string str, sz;
  gen();
  cin >> t;
  while (t--) {
    cin >> str;
    i = 4;
    n = 0;
    sz = "";
    while (i < str.size()) sz += str[i++];
    stringstream ss;
    ss << sz;
    ss >> n;
    if (sz.size() <= 3) {
      for (i = year[sz.size()][0]; i <= year[sz.size()][1]; i++) {
        if (i % _pow(10, sz.size()) == n) {
          cout << i << "\n";
          break;
        }
      }
    } else {
      string tut, fst, lst;
      for (i = 0; i < sz.size(); i++) tut += "9";
      stringstream sssf, sssl;
      sssf << year[sz.size()][0];
      sssf >> fst;
      sssl << year[sz.size()][1];
      sssl >> lst;
      if (sz >= fst && sz <= tut)
        cout << sz << "\n";
      else
        cout << "1" + sz << "\n";
    }
  }
  return 0;
}
