#include <bits/stdc++.h>
using namespace std;
void no() {
  cout << "NO\n";
  exit(0);
}
void yes() { cout << "YES\n"; }
map<string, int> matched;
void solve() {
  string s;
  cin >> s;
  int it = s.find("'");
  s = s.substr(it + 1, ((long long)s.size()) - it - 1);
  int doneupto = ((long long)s.size());
  map<string, string> curmatch;
  for (int j = (int)((long long)s.size()) - 1; j >= (int)0; j--) {
    if (not matched.count(s.substr(j, ((long long)s.size()) - j)))
      break;
    else {
      curmatch[to_string(matched[s.substr(j, ((long long)s.size()) - j)])] =
          s.substr(j, ((long long)s.size()) - j);
      doneupto = j;
    }
  }
  if (doneupto == 0) {
    cout << matched[s] << "\n";
    return;
  }
  map<string, string> ans;
  42;
  for (int i = (int)doneupto - 1; i >= (int)0; i--) {
    string cur = s.substr(i, ((long long)s.size()) - i);
    if (((long long)cur.size()) > 4) {
      if (curmatch.count(cur) or cur[0] == '0') {
        string key = "1" + cur;
        assert(curmatch.count(key) == 0);
        curmatch[key] = cur;
        ans[cur] = key;
      } else {
        curmatch[cur] = cur;
        ans[cur] = cur;
      }
    } else {
      string key = "1" + cur;
      curmatch[key] = cur;
      ans[cur] = key;
    }
  }
  cout << ans[s] << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (int i = (int)1989; i < (int)9999 + 1; i++) {
    string s = to_string(i);
    for (int j = (int)((long long)s.size()) - 1; j >= (int)0; j--) {
      string cur = s.substr(j, ((long long)s.size()) - j);
      if (matched.count(cur) == 0) {
        matched[cur] = i;
        break;
      }
    }
  }
  int t = 1;
  cin >> t;
  for (int tc = 1; tc <= t; tc++) {
    solve();
  }
}
