#include <bits/stdc++.h>
const long long INF = 4e18L + 1;
const int IINF = 2e9 + 1;
const int limit = 1048576;
using namespace std;
map<long long, long long> M;
long long odp(long long n, long long cyfr) {
  long long pot = 1;
  for (int i = 0; i < cyfr - 1; i++) pot *= 10;
  if (cyfr == 1) return M[n];
  long long cyfra = n / pot;
  long long pom = odp(n - cyfra * pot, cyfr - 1);
  if ((n % pot) / (pot / 10) == 0) {
    long long test;
    for (long long i = 0; true; i++) {
      test = n + i * pot * 10ll;
      if (test > pom) return test;
    }
  }
  long long cyfra_odp = (pom % (pot * 10)) / pot;
  long long roz = cyfra - cyfra_odp;
  if (roz <= 0) roz += 10;
  return pom + roz * pot;
}
int main() {
  int n;
  cin >> n;
  string S;
  vector<pair<long long, int> > V;
  for (int i = 0; i < n; i++) {
    cin >> S;
    S.erase(S.begin());
    S.erase(S.begin());
    S.erase(S.begin());
    S.erase(S.begin());
    long long pom = atoi(S.c_str());
    V.push_back({pom, S.size()});
  }
  M[9] = 1989;
  M[0] = 1990;
  M[1] = 1991;
  M[2] = 1992;
  M[3] = 1993;
  M[4] = 1994;
  M[5] = 1995;
  M[6] = 1996;
  M[7] = 1997;
  M[8] = 1998;
  for (auto el : V) {
    cout << odp(el.first, el.second) << "\n";
  }
  return 0;
}
