#include <bits/stdc++.h>
using namespace std;
const int dx[8] = {0, -1, 0, 1, -1, -1, 1, 1},
          dy[8] = {1, 0, -1, 0, -1, 1, -1, 1};
int main() {
  int n;
  cin >> n;
  while (n--) {
    string str1;
    cin >> str1;
    str1 = str1.substr(4);
    if (str1.size() == 1) {
      if (str1 >= "0" && str1 <= "8")
        cout << "199" + str1 << endl;
      else
        cout << "1989" << endl;
    }
    if (str1.size() == 2) {
      if (str1 == "99")
        cout << "19" + str1 << endl;
      else
        cout << "20" + str1 << endl;
    }
    if (str1.size() == 3) {
      if (str1 >= "000" && str1 <= "098")
        cout << "3" + str1 << endl;
      else
        cout << "2" + str1 << endl;
    }
    if (str1.size() == 4) {
      if (str1 >= "3099" && str1 <= "9999")
        cout << str1 << endl;
      else
        cout << "1" + str1 << endl;
    }
    if (str1.size() == 5) {
      if (str1 >= "13099" && str1 <= "99999")
        cout << str1 << endl;
      else
        cout << "1" + str1 << endl;
    }
    if (str1.size() == 6) {
      if (str1 >= "113099" && str1 <= "999999")
        cout << str1 << endl;
      else
        cout << "1" + str1 << endl;
    }
    if (str1.size() == 7) {
      if (str1 >= "1113099" && str1 <= "9999999")
        cout << str1 << endl;
      else
        cout << "1" + str1 << endl;
    }
    if (str1.size() == 8) {
      if (str1 >= "11113099" && str1 <= "99999999")
        cout << str1 << endl;
      else
        cout << "1" + str1 << endl;
    }
    if (str1.size() == 9) {
      if (str1 >= "111113099" && str1 <= "999999999")
        cout << str1 << endl;
      else
        cout << "1" + str1 << endl;
    }
  }
  return 0;
}
