#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d\n", &n);
  while (n--) {
    char number[20];
    scanf("IAO'%s\n", number);
    long long v = 1, start = 1989, i, len = strlen(number), pf = 0;
    sscanf(number, "%lld", &i);
    while (--len) v *= 10, start += v;
    v *= 10;
    while (v * pf + i < start) {
      pf++;
    }
    printf("%lld\n", v * pf + i);
  }
  return 0;
}
