#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
int now;
char s[19];
int main() {
  int t = read();
  while (t--) {
    scanf("%s", s);
    int l = strlen(s), o = l - 4;
    now = 0;
    for (int i = 4; i <= l - 1; i++) now = now * 10 + (s[i] - 48);
    if (o == 1) printf("%d\n", 1989 + (now + 1) % 10);
    if (o == 2) printf("%d\n", 1999 + (now + 1) % 100);
    if (o == 3) printf("%d\n", 2099 + (now + 901) % 1000);
    if (o == 4) printf("%d\n", 3099 + (now + 6901) % 10000);
    if (o == 5) printf("%d\n", 13099 + (now + 86901) % 100000);
    if (o == 6) printf("%d\n", 113099 + (now + 886901) % 1000000);
    if (o == 7) printf("%d\n", 1113099 + (now + 8886901) % 10000000);
    if (o == 8) printf("%d\n", 11113099 + (now + 88886901) % 100000000);
    if (o == 9) printf("%d\n", 111113099 + (now + 888886901) % 1000000000);
  }
  return 0;
}
