#include <bits/stdc++.h>
using namespace std;
int N;
int main() {
  cin >> N;
  string s;
  for (int i = 0; i < N; i++) {
    cin >> s;
    string a;
    for (int i = 4; i < s.length(); i++) {
      a += s[i];
    }
    int passed = 0;
    int tenPow = 10;
    for (int j = 1; j < a.length(); j++) {
      passed += tenPow;
      tenPow *= 10;
    }
    int ans = stoi(a);
    while (ans < 1989 + passed) {
      ans += tenPow;
    }
    cout << ans << endl;
  }
}
