#include <bits/stdc++.h>
using namespace std;
const int maxn = 100;
char str[maxn];
int main() {
  int n;
  scanf("%d", &n);
  getchar();
  while (n--) {
    for (int i = 0; i < 4; ++i) getchar();
    int s0 = 0, t = 0, ls = 0, a = 1, b = 1;
    char c = getchar();
    while (isdigit(c)) {
      str[ls++] = c;
      c = getchar();
    }
    for (int i = 0; i < ls - 1; ++i) {
      a *= 10;
      b = b * 10 + 1;
    }
    str[ls] = '\0';
    for (int i = 0; i < ls; ++i) t = t * 10 + str[i] - '0';
    if (ls == 1) {
      if (t == 9)
        puts("1989");
      else
        printf("199%c\n", str[0]);
    } else if (ls == 2) {
      if (t == 99)
        puts("1999");
      else
        printf("20%s\n", str);
    } else if (ls == 3) {
      if (t < 99)
        printf("3%s\n", str);
      else
        printf("2%s\n", str);
    } else {
      b -= 1111;
      b += 3099;
      if (t < b)
        printf("1%s\n", str);
      else
        printf("%s\n", str);
    }
  }
  return 0;
}
