#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int t;
long long ten[15] = {1};
long long check[15] = {1989};
char s[N];
int main() {
  for (int i = 1; i < 15; ++i) ten[i] = ten[i - 1] * 10;
  for (int i = 1; i < 15; ++i) check[i] = check[i - 1] + ten[i];
  scanf("%d", &t);
  while (t--) {
    scanf("%s", s);
    char *p = strtok(s, "IAO'");
    int len = strlen(p);
    long long n = atoi(p);
    if (n < check[len - 1]) {
      long long increment = check[len - 1] - n;
      n += (increment + ten[len] - 1) / ten[len] * ten[len];
    }
    cout << n << endl;
  }
}
