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