#include <bits/stdc++.h>
using namespace std;
char str[100];
long long radix, start;
int main() {
  int T;
  cin >> T;
  getchar();
  while (T--) {
    scanf("IAO\'%s", str);
    int len = strlen(str);
    start = 1988;
    radix = 1;
    for (int i = len - 1; i >= 0; i--) {
      int target = atoi(str + i);
      start += radix;
      while (start % (radix * 10) != target) {
        start += radix;
      }
      radix *= 10;
    }
    cout << start << endl;
    getchar();
  }
  return 0;
}
