#include <bits/stdc++.h>
using namespace std;
bool check(string s1, string s2) {
  long long num1 = 0, num2 = 0;
  for (long long i = 0; i < s1.length(); i++) num1 = num1 * 10 + (s1[i] - '0');
  for (long long i = 0; i < s2.length(); i++) num2 = num2 * 10 + (s2[i] - '0');
  return (num1 <= num2);
}
string con(long long num) {
  string t = "";
  while (num != 0) {
    long long mod = num % 10;
    t += (char)(mod + (int)'0');
    num = num / 10;
  }
  reverse(t.begin(), t.end());
  return t;
}
long long con2(string s) {
  long long num = 0;
  for (long long i = 0; i < s.length(); i++) {
    num = num * 10 + (s[i] - '0');
  }
  return num;
}
int main() {
  long long s, f = 1988;
  long long sum = 1LL;
  vector<long long> start;
  vector<long long> finish;
  start.push_back(0);
  finish.push_back(0);
  vector<long long> adds, addf;
  adds.push_back(0);
  addf.push_back(0);
  for (long long i = 1; i <= 10; i++) {
    s = f + 1;
    sum = sum * 10;
    f = s + sum - 1;
    start.push_back(s);
    finish.push_back(f);
    string s1 = con(s);
    string s2 = con(f);
    string s3 = "";
    string s4 = "";
    for (long long j = 0; j < s1.length() - i; j++) s3 += s1[j];
    for (long long j = 0; j < s2.length() - i; j++) s4 += s2[j];
    adds.push_back(con2(s3));
    addf.push_back(con2(s4));
  }
  int cases;
  scanf("%d", &cases);
  while (cases--) {
    string str;
    cin >> str;
    long long idx = 0;
    for (long long i = 0; i < str.length(); i++) {
      if (str[i] >= '0' && str[i] <= '9') {
        idx = i;
        break;
      }
    }
    string s = "";
    long long digit = str.length() - idx;
    for (long long i = idx; i < str.length(); i++) {
      s += str[i];
    }
    long long downlimitint = start[digit];
    long long uplimitint = finish[digit];
    string sd = con(downlimitint);
    string su = con(uplimitint);
    bool f = check(sd, s) && check(s, su);
    if (f == false) {
      long long p = adds[digit];
      long long q = addf[digit];
      for (long long i = p; i <= q; i++) {
        string temp = s;
        temp = con(i) + temp;
        f = check(sd, temp) && check(temp, su);
        if (f) {
          s = temp;
          break;
        }
      }
    }
    cout << s << endl;
  }
}
