#include <bits/stdc++.h>
int n, len, lmt, year;
char buf[(20)];
int main() {
  scanf("%d", &n);
  while (n--) {
    scanf("%s", buf);
    len = strlen(buf + 4);
    year = atoi(buf + 4);
    lmt = 1989;
    int tmp = 10;
    for (int i = 1; i < len; ++i, tmp *= 10) {
      lmt += tmp;
    }
    while (year < lmt) {
      year += tmp;
    }
    printf("%d\n", year);
  }
  return 0;
}
