#include <bits/stdc++.h>
using namespace std;
long long a[11] = {0,      1989,    1999,     2099,      3099,      13099,
                   113099, 1113099, 11113099, 111113099, 1111113099},
          M = 1e16;
char buff[100];
long long pw(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b % 2) res = res * a;
    if (b /= 2) a = a * a;
  }
  return res;
}
long long f(char* s) {
  long long len = strlen(s);
  stringstream str(s);
  long long x;
  str >> x;
  long long res = a[len] + (x + M - a[len]) % pw(10, len);
  return res;
}
int main() {
  long long n;
  cin >> n;
  while (n--) {
    cin >> buff;
    cout << f(buff + 4) << "\n";
  }
  return 0;
}
