#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, string> mp;
  for (int i = 1989; i <= 100000; i++) {
    string s = to_string(i);
    for (int j = 1; j <= s.size(); j++) {
      string t = s.substr(s.size() - j, j);
      if (!mp.count(t)) {
        mp[t] = s;
        break;
      }
    }
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    s = s.substr(4);
    if (mp.count(s)) {
      cout << mp[s] << endl;
    } else {
      if (s.size() == 5 && "00000" <= s && s <= "13098") {
        s = "1" + s;
      } else if (s.size() == 6 && "000000" <= s && s <= "113098") {
        s = "1" + s;
      } else if (s.size() == 7 && "0000000" <= s && s <= "1113098") {
        s = "1" + s;
      } else if (s.size() == 8 && "00000000" <= s && s <= "11113098") {
        s = "1" + s;
      } else if (s.size() == 9 && "000000000" <= s && s <= "111113098") {
        s = "1" + s;
      } else if (s.size() == 10 && "0000000000" <= s && s <= "1111113098") {
        s = "1" + s;
      }
      cout << s << endl;
    }
  }
}
