#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const int mod = 1000000007;
const double pi = acos(-1);
inline void gn(long long& x) {
  int sg = 1;
  char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  c == '-' ? (sg = -1, x = 0) : (x = c - '0');
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= sg;
}
inline void gn(int& x) {
  long long t;
  gn(t);
  x = t;
}
inline void gn(unsigned long long& x) {
  long long t;
  gn(t);
  x = t;
}
long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }
long long powmod(long long a, long long x, long long mod) {
  long long t = 1ll;
  while (x) {
    if (x & 1) t = t * a % mod;
    a = a * a % mod;
    x >>= 1;
  }
  return t;
}
set<long long> st;
long long t;
long long solve(long long a) {
  if (a >= 1989 && !st.count(a)) {
    st.insert(a);
    return a;
  }
  a -= t;
  while (true) {
    a += t;
    if (a < 1989) continue;
    if (st.count(a)) continue;
    st.insert(a);
    return a;
  }
}
int main() {
  int n;
  long long a;
  char s[15];
  scanf("%d", &n);
  getchar();
  for (int i = (1); i <= (n); i++) {
    scanf("IAO'%s", s);
    getchar();
    st.clear();
    int len = strlen(s);
    a = 0;
    long long k = 1ll;
    long long ans;
    for (int i = 0; i < len; ++i) a = a * 10 + s[i] - '0';
    for (int i = 1; i <= len; ++i) {
      k *= 10;
      t = k;
      ans = solve(a % k);
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
