#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int getint() {
  int r = 0, k = 1;
  char c = getchar();
  for (; '0' > c || c > '9'; c = getchar())
    if (c == '-') k = -1;
  for (; '0' <= c && c <= '9'; c = getchar()) r = r * 10 - '0' + c;
  return r * k;
}
const int le[15] = {0,     1989,   1999,    2099,     3099,
                    13099, 113099, 1113099, 11113099, 111113099};
const int ri[15] = {0,      1998,    2098,     3098,      13098,
                    113098, 1113098, 11113098, 111113098, 1111113098};
const int sh[15] = {0,      10,      100,      1000,      10000,
                    100000, 1000000, 10000000, 100000000, 1000000000};
char str[100], dst[100];
int main() {
  int T = getint(), n;
  while (T--) {
    scanf("%s", str);
    n = 0;
    int len = strlen(str);
    for (int i = 4; i < len; ++i) {
      n = n * 10 - '0' + str[i];
      dst[i - 4] = str[i];
    }
    len -= 4;
    dst[len] = 0;
    int L = le[len], R = ri[len];
    int suf = sh[len], l = le[len] % suf, r = suf - 1;
    if (l <= n && n <= r) {
      if (L / suf)
        printf("%d%s\n", L / suf, dst);
      else
        printf("%s\n", dst);
    } else {
      if (R / suf)
        printf("%d%s\n", R / suf, dst);
      else
        printf("%s\n", dst);
    }
  }
}
