#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const string kPrefix = "IAO'";
const ll kStart = 1989;
const ll kBuben = 100000;
inline ll to_ll(const string& x) {
  ll res = 0;
  for (char c : x) {
    res = (10 * res) + (c - '0');
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  map<string, string> reses;
  for (ll year = kStart; year <= kBuben; year++) {
    auto s = to_string(year);
    for (int i = 1; i <= s.size(); i++) {
      string suf = s.substr(s.size() - i);
      if (reses.count(suf) == 0) {
        reses[suf] = s;
        break;
      }
    }
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string name;
    cin >> name;
    name = name.substr(kPrefix.size());
    auto res = reses.find(name);
    if (res == reses.end()) {
      string bad = "3098";
      while (bad.size() < name.size()) bad = "1" + bad;
      if (name[0] == '0' || bad >= name) name = "1" + name;
      cout << name << "\n";
    } else {
      cout << res->second << "\n";
    }
  }
  return 0;
}
