#include <bits/stdc++.h>
using namespace std;
char s[15];
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    scanf(" %s", s);
    int k = strlen(s + 4), year = atoi(s + 4), tenPow = 10, f = 0;
    for (int i = 1; i < k; i++) {
      f += tenPow;
      tenPow *= 10;
    }
    while (year < 1989 + f) year += tenPow;
    printf("%d\n", year);
  }
  return 0;
}
