#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN = 25;
int t;
char s[MAXN];
int main(int argc, char const *argv[]) {
  scanf("%d", &t);
  while (t--) {
    scanf("%s", s);
    strcpy(s, s + 4);
    long long num = 1989, i, k, d = 10;
    for (i = 0, k = 0; i < strlen(s); ++i) k = 10 * k + (s[i] - '0');
    for (long long j = 2; j <= i; ++j) {
      num += d;
      d *= 10;
    }
    for (i = 0; i * d + k < num; ++i)
      ;
    printf("%lld\n", i * d + k);
  }
  return 0;
}
