#include <bits/stdc++.h>
int len;
char s[11];
void func(long long int num) {
  long long int ans = 3099, l = 4, t = 10000;
  while (l < len) {
    ans = t + ans;
    t = t * 10;
    l++;
  }
  if (num < ans) {
    printf("1");
    printf("%s\n", s);
  } else {
    printf("%s\n", s);
  }
}
int main() {
  int test;
  scanf("%d", &test);
  while (test--) {
    int i;
    char c;
    long long int t, num = 0;
    while (1) {
      scanf("%c", &c);
      if (c == '\'') {
        scanf("%s", s);
        break;
      }
    }
    for (i = 0, len = 0; s[i] != 0; i++, len++) {
      num = num * 10 + (s[i] - '0');
    }
    if (len > 3) {
      func(num);
      continue;
    } else if (len == 3) {
      if (num > 98 && num != 0) {
        printf("2");
      } else {
        printf("3");
      }
      printf("%s\n", s);
    } else if (len == 2) {
      if (num == 99) {
        printf("1999\n");
      } else {
        printf("20");
        printf("%s\n", s);
      }
    } else if (len == 1) {
      if (num == 9) {
        printf("198");
        printf("%s\n", s);
      } else {
        printf("199");
        printf("%s\n", s);
      }
    }
  }
  return 0;
}
