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