#include <bits/stdc++.h>
using namespace std;
string s;
int d[100010], n;
int main() {
  cin >> n;
  memset(d, 0, sizeof(d));
  for (int i = 1; i <= n; i++) {
    cin >> s;
    s = s.substr(4);
    int k = atoi(s.c_str());
    int len = s.size();
    int g = 1;
    int last = 1988;
    for (int j = 1; j <= len; j++) {
      g *= 10;
      if (k % g <= last % g) {
        last = (last / g + 1) * g + k % g;
      } else {
        last = (last / g) * g + k % g;
      }
    }
    cout << last << "\n";
  }
}
