#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
inline void init() {
  for (int i = 1989; i <= 3998; i++) {
    int tp = i;
    string t = "";
    while (tp) {
      if (t == "" || mp.count(t)) t = char(tp % 10 + '0') + t, tp /= 10;
      if (!mp.count(t)) {
        mp[t] = i;
        break;
      }
    }
  }
}
int main() {
  init();
  int n;
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  while (n--) {
    string num;
    cin >> num;
    num = num.substr(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) num = "1" + num;
      cout << num << endl;
    }
  }
}
