#include <bits/stdc++.h>
using namespace std;
long long p10[100] = {
    1LL,       10LL,       100LL,       1000LL,       10000LL,       100000LL,
    1000000LL, 10000000LL, 100000000LL, 1000000000LL, 10000000000LL,
};
long long n, i, x, ls;
long long l[22], r[22];
char ch, s[100];
int main() {
  l[1] = 1989;
  r[1] = 1998;
  for (i = 2; i <= 10; i++) {
    l[i] = r[i - 1] + 1;
    r[i] = l[i] + p10[i] - 1;
  }
  scanf("%I64d\n", &n);
  while (n--) {
    while (scanf("%c", &ch) && ch != '\'')
      ;
    scanf("%s", s);
    ls = strlen(s);
    x = 0;
    for (i = 0; i < ls; i++) x = x * 10 + s[i] - '0';
    while (x < l[ls]) x += p10[ls];
    printf("%I64d\n", x);
  }
  return 0;
}
