#include <bits/stdc++.h>
using namespace std;
char S[20];
int n, m, x, y, z, k, w, tmp;
int find(int x, int pre, int dig) {
  int tmp = 1;
  for (int i = (0); i < (dig); i++) tmp *= 10;
  int y = pre / tmp;
  if (y * tmp + x <= pre) y++;
  return y * tmp + x;
}
int main() {
  scanf("%d", &n);
  for (int i = (0); i < (n); i++) {
    scanf("%s", S);
    m = strlen(S);
    tmp = 1;
    w = 1988;
    y = 0;
    for (int i = (m - 1); i >= (4); i--) {
      x = S[i] - 48;
      y += x * tmp;
      w = find(y, w, m - i);
      tmp *= 10;
    }
    printf("%d\n", w);
  }
  return 0;
}
