#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int maxN = 1 << 17;
void ans1(char* T) {
  if (*T == '9')
    printf("1989\n");
  else
    printf("199%c\n", *T);
}
void ans2(char* t) {
  if (t[0] == '9' and t[1] == '9')
    printf("1999\n");
  else
    printf("20%c%c\n", t[0], t[1]);
}
void ans3(char* t) {
  int n = atoi(t);
  if (n < 99)
    printf("3%s\n", t);
  else
    printf("2%s\n", t);
}
void solve(char* T) {
  int n = strlen(T);
  if (n == 1) {
    ans1(T);
    return;
  }
  if (n == 2) {
    ans2(T);
    return;
  }
  if (n == 3) {
    ans3(T);
    return;
  }
  long long m = atoi(T);
  char W[42];
  W[n] = 0;
  for (int i = (0); i < (int)(n - 4); i++) W[i] = '1';
  W[n - 4] = '3';
  W[n - 3] = '0';
  W[n - 2] = '9';
  W[n - 1] = '9';
  if (atoi(T) < atoi(W)) printf("1");
  printf("%s\n", T);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    char in[42];
    scanf("%s", in);
    solve(in + 4);
  }
  return 0;
}
