#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
int dxx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
int dyy[] = {0, +1, 0, -1, +1, -1, +1, -1};
inline bool checkBit(long long n, int i) { return n & (1LL << i); }
inline long long setBit(long long n, int i) { return n | (1LL << i); }
inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
long long bigMod(long long a, long long b) {
  long long r = 1;
  while (b) {
    if (b & 1) (r *= a) %= 1000000007;
    b >>= 1;
    (a *= a) %= 1000000007;
  }
  return r;
}
int main() {
  int tc;
  char s[107];
  long long y, cmp, i, j, r;
  scanf("%d", &tc);
  while (tc--) {
    scanf("%s", s);
    y = 0;
    int cnt = strlen(s) - 4;
    for (i = 4; s[i]; i++) y = y * 10 + (s[i] - '0');
    cmp = 1988;
    i = 10;
    r = 0;
    while (cnt--) {
      r = y % i;
      for (j = 0; j * i + r <= cmp; j++)
        ;
      cmp = j * i + r;
      i *= 10;
    }
    printf("%lld\n", cmp);
  }
  return 0;
}
