#include <bits/stdc++.h>
using namespace std;
int i, j, mini = 1000000000, p, n, m, k, ok, ul, op, maxi = -1, ls, ld, mij,
          rest, besto, a;
set<string> myset;
string s3;
int s1[10000], s2[10000];
string oo;
stack<int> sta;
map<int, int> mymap;
int cifre[100];
char obiect[100005];
int f1, f2, f3, f4;
pair<int, int> b, c, v[500005];
long double total;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  int minj;
  for (i = 1; i <= n; i++) {
    minj = 9996;
    for (j = 0; j <= 9999; j++) s1[j] = s2[j] = 0;
    cin >> s3;
    p = s3.size();
    for (m = 4; m < p; m++) s1[m - 3] = s3[m] - 48;
    m -= 4;
    j = 9999;
    s2[j] = s1[m];
    s2[j - 1] = 9;
    s2[j - 2] = 9;
    s2[j - 3] = 1;
    if (s1[m] == 9) s2[j - 1] = 8;
    m--;
    while (m) {
      j--;
      if (s1[m] <= s2[j]) {
        a = j - 1;
        s2[a]++;
        while (s2[a] > 9) {
          s2[a] %= 10;
          a--;
          s2[a]++;
        }
        if (a < minj) minj = a;
      }
      s2[j] = s1[m];
      m--;
    }
    if (j < minj) minj = j;
    for (j = minj; j <= 9999; j++) cout << s2[j];
    cout << '\n';
  }
  return 0;
}
