#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int k = s.size() - 4, f = 0, power = 10;
    string hoge = s.substr(4);
    int y = atoi(hoge.c_str());
    for (int i = 0; i < k - 1; i++) {
      f += power;
      power *= 10;
    }
    while (y < 1989 + f) y += power;
    cout << y << endl;
  }
}
