#include <bits/stdc++.h>
using namespace std;
unordered_map<string, string> cache;
void rec(string &cur, unordered_set<string> &s, int rem) {
  if (rem == 0) {
    s.insert(cur);
    return;
  }
  for (int i = 0; i <= 9; ++i) {
    cur.push_back('0' + i);
    rec(cur, s, rem - 1);
    cur.pop_back();
  }
}
void comp() {
  unordered_set<string> unused;
  for (int i = 1; i <= 5; ++i) {
    string cur;
    rec(cur, unused, i);
  }
  for (int i = 1989; i <= 99999; ++i) {
    string s = to_string(i);
    for (int j = 1; j <= (int)s.size(); ++j) {
      string sub = s.substr(s.size() - j, j);
      auto it = unused.find(sub);
      if (it != unused.end()) {
        unused.erase(it);
        if (j != s.size()) cache.emplace(sub, s);
        break;
      }
    }
  }
}
int main() {
  comp();
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    s = s.substr(4);
    if (s.length() <= 4) {
      auto it = cache.find(s);
      if (it == cache.end()) {
        cout << s << endl;
      } else {
        cout << it->second << endl;
      }
    } else {
      if (s[0] == '0') {
        cout << '1';
      } else if (s[0] == '1') {
        string ss(s.rbegin(), s.rend());
        while (ss.size() > 4 && ss.back() == '1') {
          ss.pop_back();
        }
        reverse(ss.begin(), ss.end());
        if (ss.front() == '0' || cache.count(ss) > 0) {
          cout << '1';
        }
      }
      cout << s << endl;
    }
  }
}
