#include <bits/stdc++.h>
using namespace std;
string ans(string s) {
  int len = s.length();
  long long x = 0, y = stoll(s);
  long long pw10 = 10;
  for (int i = 1; i < len; i++) {
    x += pw10;
    pw10 *= 10;
  }
  long long mn = max(0LL, (1989 + x - y) / pw10);
  while (mn * pw10 + y < 1989 + x) mn++;
  return to_string(mn * pw10 + y);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    string s1 = s.substr(4, s.length() - 4);
    cout << ans(s1) << endl;
  }
}
