#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    s = s.substr(4, s.size() - 4);
    switch (s.size()) {
      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 < "099")
          cout << "3" << s;
        else
          cout << "2" << s;
        break;
      case 4:
        if (s <= "3098")
          cout << "1" << s;
        else
          cout << s;
        break;
      case 5:
        if (s <= "13098")
          cout << "1" << s;
        else
          cout << s;
        break;
      case 6:
        if (s <= "113098")
          cout << "1" << s;
        else
          cout << s;
        break;
      case 7:
        if (s <= "1113098")
          cout << "1" << s;
        else
          cout << s;
        break;
      case 8:
        if (s <= "11113098")
          cout << "1" << s;
        else
          cout << s;
        break;
      case 9:
        if (s <= "111113098")
          cout << "1" << s;
        else
          cout << s;
        break;
    }
    cout << endl;
  }
}
