#include <bits/stdc++.h>
using namespace std;
const int maxn = 15;
char str[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%s", str);
    int num = 0, cnt = 0;
    for (int i = 0; str[i]; ++i)
      if (isdigit(str[i])) {
        num = num * 10 + str[i] - '0';
        ++cnt;
      }
    if (cnt == 1) {
      if (num == 9)
        puts("1989");
      else
        printf("199%d\n", num);
    } else if (cnt == 2) {
      if (num == 99)
        puts("1999");
      else
        printf("20%02d\n", num);
    } else if (cnt == 3) {
      if (num >= 99)
        printf("2%03d\n", num);
      else
        printf("3%03d\n", num);
    } else if (cnt == 4) {
      if (num >= 3099)
        printf("%d\n", num);
      else
        printf("1%04d\n", num);
    } else if (cnt == 5) {
      if (num >= 13099)
        printf("%d\n", num);
      else
        printf("1%05d\n", num);
    } else if (cnt == 6) {
      if (num >= 113099)
        printf("%d\n", num);
      else
        printf("1%06d\n", num);
    } else if (cnt == 7) {
      if (num >= 1113099)
        printf("%d\n", num);
      else
        printf("1%07d\n", num);
    } else if (cnt == 8) {
      if (num >= 11113099)
        printf("%d\n", num);
      else
        printf("1%08d\n", num);
    } else {
      if (num >= 111113099)
        printf("%d\n", num);
      else
        printf("1%09d\n", num);
    }
  }
  return 0;
}
