#include <bits/stdc++.h>
using namespace std;
char s[100];
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    scanf(" IAO'%s", s);
    long long so = 0;
    long long lt = 1;
    long long bound = 1988;
    for (int i = 0; s[i] != 0; i++) {
      so = so * 10 + s[i] - '0';
      lt *= 10;
    }
    for (long long hehe = 10; hehe <= lt; hehe *= 10) {
      long long soso = so % hehe;
      for (int i = 0; i < 1000; i++) {
        long long tmp = soso + i * hehe;
        if (tmp > bound) {
          bound = tmp;
          break;
        }
      }
    }
    printf("%I64d\n", bound);
  }
  return 0;
}
