#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9 + 100;
const long double eps = 1e-12;
const long double pi = acos(-1.0L);
int myrand() { return rand(); }
unsigned rdtsc() {
  unsigned ans;
  asm("rdtsc" : "=a"(ans));
  return ans;
}
int rnd(int x) { return myrand() % x; }
void precalc() {}
const int maxm = 62;
int n;
bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  return true;
}
void solve() {
  for (int it = 0; it < n; it++) {
    char s[100];
    scanf(" IAO'%s", s);
    int len = strlen(s);
    long long prev = 1988;
    long long ten = 10;
    for (int i = len - 1; i >= 0; i--) {
      long long cur = 0;
      for (int j = i; j < len; j++) {
        cur *= 10;
        cur += s[j] - '0';
      }
      if (prev < cur) {
        cur += (prev - cur + ten - 1) / ten;
      }
      while (cur <= prev) {
        cur += ten;
      }
      prev = cur;
      ten *= 10;
    }
    printf(
        "%lld"
        "\n",
        prev);
  }
}
int main() {
  srand(rdtsc());
  precalc();
  while (true) {
    if (!read()) {
      break;
    }
    solve();
  }
  return 0;
}
