#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  string s;
  for (int _ = 0; _ < (int)(n); _++) {
    cin >> s;
    int len = s.size() - 4;
    int t = atoi(s.substr(4).c_str());
    int k = 10;
    int wow = 0;
    for (int p = 1; p < len; p++) {
      wow += k;
      k *= 10;
    }
    while (t < 1989 + wow) {
      t += k;
    }
    cout << t << '\n';
  }
}
