#include <bits/stdc++.h>
using namespace std;
string f(int t) { return t == 0 ? "" : "1" + f(t - 1); }
string anw(string x) {
  if (x.size() == 1) return x[0] == '9' ? "1989" : "199" + x;
  if (x.size() == 2) return x == "99" ? "1999" : "20" + x;
  if (x.size() == 3)
    return x == "099" ? "2099" : (x < "099" ? "3" + x : "2" + x);
  return x < f(x.size() - 4) + "3099" ? "1" + x : x;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string t;
    cin >> t;
    string a = t.substr(4);
    cout << anw(a) << endl;
  }
}
