#include <bits/stdc++.h>
using namespace std;
string str;
int n;
int main() {
  cin >> n;
  while (n--) {
    cin >> str;
    str = str.substr(4);
    int year = stoi(str);
    int st = 1989, val = 10;
    for (int i = 1; i < str.size(); i++) {
      st += val;
      val *= 10;
    }
    while (st > year) year += val;
    cout << year << endl;
  }
}
