#include <bits/stdc++.h>
using namespace std;
void read() {}
string toint(string s) {
  string tmp;
  int l = s.size();
  long long int ans = 0;
  for (int i = 0; i < l; i++)
    if (s[i] >= '0' && s[i] <= '9') tmp.push_back(s[i]);
  return tmp;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  read();
  string s;
  map<string, long long int> mp;
  int len = 0;
  mp["9"] = 1989;
  mp["0"] = 1990;
  mp["1"] = 1991;
  mp["2"] = 1992;
  mp["3"] = 1993;
  mp["4"] = 1994;
  mp["5"] = 1995;
  mp["6"] = 1996;
  mp["7"] = 1997;
  mp["8"] = 1998;
  mp["99"] = 1999;
  mp["00"] = 2000;
  mp["999"] = 2999;
  mp["9999"] = 9999;
  mp["99999"] = 99999;
  mp["99999"] = 99999;
  mp["999999"] = 999999;
  mp["9999999"] = 9999999;
  mp["99999999"] = 99999999;
  mp["999999999"] = 999999999;
  mp["9999999999"] = 9999999999;
  int tc;
  cin >> tc;
  while (tc--) {
    cin >> s;
    string tmp = toint(s);
    int l = tmp.size();
    if (mp[tmp])
      cout << mp[tmp] << "\n";
    else if (l == 2)
      cout << "20" << tmp << "\n";
    else if (l == 3) {
      if (tmp[0] == '0' && tmp != "099")
        cout << "3" << tmp << "\n";
      else
        cout << "2" << tmp << "\n";
    } else if (l == 4) {
      if (tmp >= "3099" && tmp <= "9999")
        cout << tmp << "\n";
      else
        cout << 1 << tmp << "\n";
    } else if (l == 5) {
      if (tmp >= "13099" && tmp <= "99999")
        cout << tmp << "\n";
      else
        cout << 1 << tmp << "\n";
    } else if (l == 6) {
      if (tmp >= "113099" && tmp <= "999999")
        cout << tmp << "\n";
      else
        cout << 1 << tmp << "\n";
    } else if (l == 7) {
      if (tmp >= "1113099" && tmp <= "9999999")
        cout << tmp << "\n";
      else
        cout << 1 << tmp << "\n";
    } else if (l == 8) {
      if (tmp >= "11113099" && tmp <= "99999999")
        cout << tmp << "\n";
      else
        cout << 1 << tmp << "\n";
    } else if (l == 9) {
      if (tmp >= "111113099" && tmp <= "999999999")
        cout << tmp << "\n";
      else
        cout << 1 << tmp << "\n";
    }
  }
}
