#include <bits/stdc++.h>
using namespace std;
long long ans1[13];
long long ans2[105];
long long ans3[1009];
char str[30];
int main() {
  long long i, j = 1991;
  ans1[0] = 1990;
  ans1[9] = 1989;
  for (i = 1; i <= 8; i++) {
    ans1[i] = j;
    j++;
  }
  ans2[99] = 1999;
  j = 2000;
  for (i = 0; i <= 98; i++) {
    ans2[i] = j;
    j++;
  }
  for (i = 99; i <= 999; i++) {
    ans3[i] = j;
    j++;
  }
  for (i = 0; i <= 98; i++) {
    ans3[i] = j;
    j++;
  }
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%s", str);
    long long l = strlen(str), n = 0;
    for (i = 4; i < l; i++) n = n * 10 + (str[i] - '0');
    long long len = l - 4;
    if (len == 1) {
      printf("%lld\n", ans1[n]);
      continue;
    } else if (len == 2) {
      printf("%lld\n", ans2[n]);
      continue;
    } else if (len == 3) {
      printf("%lld\n", ans3[n]);
      continue;
    } else if (len == 4) {
      if (n > 3098)
        int yyy = 1;
      else
        printf("1");
    } else if (len == 5) {
      if (n > 13098)
        int yyy = 1;
      else
        printf("1");
    } else if (len == 6) {
      if (n > 113098)
        int yyy = 1;
      else
        printf("1");
    } else if (len == 7) {
      if (n > 1113098)
        int yyy = 1;
      else
        printf("1");
    } else if (len == 8) {
      if (n > 11113098)
        int yyy = 1;
      else
        printf("1");
    } else if (len == 9) {
      if (n > 111113098)
        int yyy = 1;
      else
        printf("1");
    } else {
      if (n > 1111113098)
        int yyy = 1;
      else
        printf("1");
    }
    for (i = 4; i < l; i++) printf("%c", str[i]);
    printf("\n");
  }
  return 0;
}
