#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
map<string, int>::iterator it;
void init() {
  int st = 1989;
  for (int i = st; i <= 100000; i++) {
    int tp = i;
    string t = "";
    while (tp) {
      if (t == "" || mp.count(t)) {
        t = char(tp % 10 + '0') + t;
        if (!mp.count(t)) {
          mp[t] = i;
          break;
        }
        tp /= 10;
      } else {
        mp[t] = i;
        break;
      }
    }
  }
}
char str[111];
int main() {
  init();
  int n;
  cin >> n;
  getchar();
  while (n--) {
    gets(str);
    string num = str + 4;
    if (mp.count(num))
      cout << mp[num] << endl;
    else {
      string a = "3098";
      for (int i = 4; i < num.length(); i++) a = "1" + a;
      if (num <= a)
        cout << "1" + num << endl;
      else
        cout << num << endl;
    }
  }
  return 0;
}
