#include <bits/stdc++.h>
using namespace std;
long long nn[15];
long long num[15];
long long k_pow(long long a, long long b) {
  if (b == 0) return 1;
  long long t = k_pow(a, b / 2);
  return (b & 1) ? a * t * t : t * t;
}
int main() {
  int T;
  long long a = 1989, b = 1;
  for (int i = 1; i <= 9; i++) {
    nn[i] = a;
    b *= 10;
    a += b;
  }
  scanf("%d", &T);
  getchar();
  while (T--) {
    for (int i = 0; i < 4; i++) getchar();
    int i = 0;
    while (1) {
      char c = getchar();
      if (!isdigit(c)) break;
      num[i++] = c - '0';
    }
    long long start = nn[i];
    long long test = 0, power = 1;
    for (int j = i - 1; j >= 0; j--) {
      test += num[j] * power;
      power *= 10;
    }
    while (test < start) {
      test += power;
    }
    printf("%I64d\n", test);
  }
  return 0;
}
