#include <bits/stdc++.h>
using namespace std;
int n;
char s[10000];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    int len = strlen(s);
    len = len - 4;
    long long x = 0;
    for (int i = 4; s[i]; i++) x = x * 10 + s[i] - '0';
    if (len == 1) {
      if (x == 9)
        printf("1989\n");
      else
        printf("199%d\n", x);
    }
    if (len == 2) {
      if (x == 99)
        printf("1999\n");
      else
        printf("20%02d\n", x);
    }
    if (len == 3) {
      if (x <= 98)
        printf("3%03d\n", x);
      else
        printf("2%03d\n", x);
    }
    if (len == 4) {
      if (x <= 3098)
        printf("1%04d\n", x);
      else
        printf("%04d\n", x);
    }
    if (len == 5) {
      if (x <= 13098)
        printf("1%05d\n", x);
      else
        printf("%05d\n", x);
    }
    if (len == 6) {
      if (x <= 113098)
        printf("1%06d\n", x);
      else
        printf("%06d\n", x);
    }
    if (len == 7) {
      if (x <= 1113098)
        printf("1%07d\n", x);
      else
        printf("%07d\n", x);
    }
    if (len == 8) {
      if (x <= 11113098)
        printf("1%08d\n", x);
      else
        printf("%08d\n", x);
    }
    if (len == 9) {
      if (x <= 111113098)
        printf("1%09d\n", x);
      else
        printf("%09d\n", x);
    }
  }
  return 0;
}
