#include <bits/stdc++.h>
using namespace std;
void print(vector<int> a) {
  for (int i = 0; i < a.size(); ++i) {
    cout << a[i] << " ";
  }
  cout << endl;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    s = s.substr(4, s.length() - 4);
    int curr = s.length();
    long long start = 1989LL, step = 10LL;
    for (int i = 0; i < curr - 1; ++i) {
      start += step;
      step *= 10;
    }
    int st = curr;
    if (st == 1) {
      if (s == "9")
        cout << 1989 << endl;
      else
        cout << 199 << s << endl;
    } else if (st == 2) {
      if (s == "99")
        cout << 1999 << endl;
      else
        cout << 20 << s << endl;
    } else if (st == 3) {
      if (s == "099")
        cout << 2099 << endl;
      else {
        if (s[0] == '0')
          cout << 3 << s << endl;
        else
          cout << 2 << s << endl;
      }
    } else {
      if (s[0] == '0')
        cout << 1 << s << endl;
      else {
        int chislo = 0;
        for (int i = 0; i < curr; ++i) {
          chislo *= 10;
          chislo += (s[i] - '0');
        }
        if (chislo < start)
          cout << 1 << chislo << endl;
        else
          cout << chislo << endl;
      }
    }
  }
  return 0;
}
