#include <bits/stdc++.h>
using namespace std;
const int N = 1100;
const long long INF = 1e9 + 19;
int n;
char t[100];
char s[N];
void read() {
  fgets(t, N, stdin);
  sscanf(t, "IAO'%s", s);
}
void solve() {
  int len = strlen(s);
  long long id = 1988;
  long long x = 0;
  long long g = 1;
  for (int i = len - 1; i >= 0; i--) {
    x += (s[i] - '0') * g;
    long long step = g;
    g *= 10;
    id += step;
    for (; id % g != x; id += step)
      ;
  }
  printf("%lld\n", id);
}
void stress() {}
int main() {
  if (1) {
    int k;
    scanf("%d", &k);
    fgets(s, N, stdin);
    for (int tt = 0; tt < k; tt++) {
      read();
      solve();
    }
  } else {
    stress();
  }
  return 0;
}
