#include <bits/stdc++.h>
using namespace std;
long long points[12] = {1989,      1999,       2099,        3099,
                        13099,     113099,     1113099,     11113099,
                        111113099, 1111113099, 11111113099, 0};
long long n, ndig = 0, t;
char inp[30];
int main() {
  cin >> t;
  while (t--) {
    ndig = 0;
    cin >> inp;
    n = atoll(inp + 4);
    ndig = strlen(inp) - 4;
    long long p = 1, ndigcp = ndig;
    while (ndigcp--) p *= 10;
    if (ndig <= 4) {
      for (long long i = points[ndig - 1]; i < points[ndig]; i++) {
        if (i % p == n) {
          cout << i << endl;
          break;
        }
      }
    } else {
      if (n >= points[ndig - 1]) {
        cout << n << endl;
      } else {
        cout << n + p << endl;
      }
    }
  }
  return 0;
}
