#include <bits/stdc++.h>
using namespace std;
const long long p = 1e9 + 7;
const long double pi = 3.1415926535898;
int main() {
  int t;
  cin >> t;
  while (t--) {
    bool dis = 0;
    string s;
    cin >> s;
    long long ans = 1989, d = 1, duck = 0;
    for (int i = 4; i < s.size(); i++) {
      duck = duck * 10 + (s[i] - '0');
      d *= 10;
    }
    for (long long i = 10; i <= d; i *= 10) {
      if (dis && ans % i == duck % i) {
        ans += i;
      }
      dis = 1;
      while (ans % i != duck % i) {
        ans += i / 10;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
