#include <bits/stdc++.h>
using namespace std;
map<string, int> anho;
int main() {
  int n;
  cin >> n;
  string cad;
  string suf;
  for (int i = 0; i < n; i++) {
    cin >> cad;
    cad = cad.substr(4, cad.size() - 4);
    long long pot = 1;
    long long der = 0;
    long long num;
    map<long long, bool> esta;
    map<string, long long> res;
    suf = "";
    for (int j = 0, index = cad.size() - 1; j < cad.size(); j++, index--) {
      suf = cad[index] + suf;
      der = (cad[index] - '0') * pot + der;
      if (der >= 1989 && !esta[der]) {
        esta[der] = true;
        res[suf] = der;
        pot *= 10;
        continue;
      }
      for (long long izq = 1; izq < 10000; izq++) {
        num = izq * pot * 10 + der;
        if (num >= 1989 && !esta[num]) {
          esta[num] = true;
          res[suf] = num;
          break;
        }
      }
      pot *= 10;
    }
    cout << res[cad] << endl;
    esta.clear();
    res.clear();
  }
  return 0;
}
