#include <bits/stdc++.h>
using namespace std;
const int bs[] = {1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1989};
char s[16];
int ds[16];
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    scanf("%s", s);
    char *t = s + 4;
    int l = strlen(t);
    int m = 0, t0 = t[l - 1] - '0';
    ds[m++] = t0;
    int b = bs[t0] / 10;
    for (int i = l - 2; i >= 0; i--) {
      int ti = t[i] - '0';
      ds[m++] = ti;
      int b0 = b % 10;
      b /= 10;
      if (ti <= b0) b++;
    }
    while (b > 0) {
      ds[m++] = b % 10;
      b /= 10;
    }
    for (int i = m - 1; i >= 0; i--) putchar(ds[i] + '0');
    putchar('\n');
  }
  return 0;
}
