#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  while (N--) {
    string S;
    cin >> S;
    S = S.substr(4);
    int vv = stoi(S);
    int latte = 0, fact = 10;
    for (int i = 1; i < S.size(); i++) {
      latte += fact;
      fact *= 10;
    }
    while (vv < 1989 + latte) vv += fact;
    cout << vv << endl;
  }
}
