#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  int n;
  cin >> n;
  for (int t = 0; t < n; t++) {
    string s;
    cin >> s;
    s = s.substr(4, s.length() - 4);
    switch (s.length()) {
      case 1:
        if (s == "9")
          cout << "1989";
        else
          cout << "199" + s;
        break;
      case 2:
        if (s == "99")
          cout << "1999";
        else
          cout << "20" + s;
        break;
      case 3:
        if (s == "099")
          cout << "2099";
        else if (s[0] == '0')
          cout << "3" + s;
        else
          cout << "2" + s;
        break;
      case 4:
        if (s < "3099")
          cout << "1" + s;
        else
          cout << s;
        break;
      default:
        string buf = "";
        for (int i = 4; i < s.length(); i++) buf += "1";
        if (s < (buf + "3099"))
          cout << "1" + s;
        else
          cout << s;
        break;
    }
    cout << endl;
  }
  return 0;
}
