#include <bits/stdc++.h>
using namespace std;
long long rdtsc() {
  long long tmp;
  asm("rdtsc" : "=A"(tmp));
  return tmp;
}
inline int myrand() { return abs((rand() << 15) ^ rand()); }
inline int rnd(int x) { return myrand() % x; }
void precalc() {}
int n;
bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  return true;
}
long long solve(char *s) {
  if (s[1] == 0) {
    for (long long x = 1989;; ++x) {
      if (x % 10 == s[0] - '0') {
        return x;
      }
    }
  }
  long long x = solve(s + 1);
  int k = strlen(s);
  long long p = 1;
  long long y = 0;
  for (int i = k - 1; i > 0; --i, p *= 10) {
    y += p * (s[i] - '0');
  }
  assert(y == x % p);
  if (y == x) {
    x += p * (s[0] - '0');
    if (s[0] - '0' == 0) {
      x += p * 10;
    }
    return x;
  }
  y += p * (s[0] - '0');
  for (x += p; x % (p * 10) != y; x += p)
    ;
  return x;
}
const int maxn = 100;
char s[maxn];
void solve() {
  for (int i = 0; i < n; ++i) {
    scanf("%s", s);
    printf("%I64d\n", solve(s + 4));
  }
}
int main() {
  srand(rdtsc());
  precalc();
  while (true) {
    if (!read()) {
      break;
    }
    solve();
  }
  return 0;
}
