#include <bits/stdc++.h>
using namespace std;
long long get(long long mn, long long x, long long ml) {
  long long m = (mn - x + ml - 1) / ml;
  m = max(m, 0LL);
  return m * ml + x;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    string x;
    cin >> x;
    x = x.substr(4);
    long long mn = 1989;
    long long h = 0;
    for (long long ml = 1, i = int(x.size()) - 1; i >= 0; i--, ml *= 10) {
      h += ml * (x[i] - '0');
      mn = get(mn, h, ml * 10);
      if (i) mn++;
    }
    cout << mn << endl;
  }
}
