#include <bits/stdc++.h>
using namespace std;
int q;
map<string, int> ma;
void pre() {
  for (int i = 1989; i <= 3098; i++) {
    string s = "";
    int x = i;
    while (x) {
      s = char(x % 10 + '0') + s;
      if (!ma[s]) {
        ma[s] = i;
        break;
      }
      x /= 10;
    }
  }
}
int sol(string z) { return ma[z]; }
int main() {
  pre();
  cin >> q;
  while (q--) {
    string s, z;
    cin >> s;
    z = s.substr(4);
    if (z.length() <= 3)
      cout << sol(z) << endl;
    else {
      string a = "3098";
      for (int i = 4; i < z.length(); i++) a = "1" + a;
      if (z <= a)
        cout << "1" + z << endl;
      else
        cout << z << endl;
    }
  }
  return 0;
}
