#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n;
char olimp[20];
int main() {
  scanf("%d\n", &n);
  while (n--) {
    scanf("IAO'%s\n", olimp);
    int len = strlen(olimp);
    int year = atoi(olimp);
    int ten = 10, first = 0;
    for (int i = 1; i < len; i++) {
      first += ten;
      ten *= 10;
    }
    while (year < 1989 + first) year += ten;
    printf("%d\n", year);
  }
  return 0;
}
