#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    string str;
    cin >> str;
    str = str.substr(4);
    if (str.size() == 1) {
      if (str == "9")
        cout << "198" << str << endl;
      else
        cout << "199" << str << endl;
    } else if (str.size() == 2) {
      if (str == "99")
        cout << "19" << str << endl;
      else
        cout << "20" << str << endl;
    } else if (str.size() == 3) {
      if (str >= "000" && str <= "098")
        cout << "3" << str << endl;
      else
        cout << "2" << str << endl;
    } else if (str.size() == 4) {
      if (str >= "0000" && str <= "3098")
        cout << "1" << str << endl;
      else
        cout << str << endl;
    } else if (str.size() == 5) {
      if (str >= "00000" && str <= "13098")
        cout << "1" << str << endl;
      else
        cout << str << endl;
    } else if (str.size() == 6) {
      if (str >= "000000" && str <= "113098")
        cout << "1" << str << endl;
      else
        cout << str << endl;
    } else if (str.size() == 7) {
      if (str >= "0000000" && str <= "1113098")
        cout << "1" << str << endl;
      else
        cout << str << endl;
    } else if (str.size() == 8) {
      if (str >= "00000000" && str <= "11113098")
        cout << "1" << str << endl;
      else
        cout << str << endl;
    } else if (str.size() == 9) {
      if (str >= "000000000" && str <= "111113098")
        cout << "1" << str << endl;
      else
        cout << str << endl;
    }
  }
  return 0;
}
