#include <bits/stdc++.h>
using namespace std;
template <class T, class L>
bool smax(T &x, L y) {
  return x < y ? (x = y, 1) : 0;
}
template <class T, class L>
bool smin(T &x, L y) {
  return y < x ? (x = y, 1) : 0;
}
const int maxn = 2e5 + 17;
int n, po[10];
string base[] = {"sipa :P", "1989",   "1999",    "2099",     "3099",
                 "13099",   "113099", "1113099", "11113099", "111113099"};
char s[17];
int to_int(string &s) {
  stringstream tmp;
  tmp << s;
  int x;
  tmp >> x;
  return x;
}
int main() {
  int n;
  scanf("%d", &n);
  getchar();
  po[0] = 1;
  for (int i = 1; i < 10; i++) po[i] = po[i - 1] * 10;
  while (n--) {
    scanf("IAO'%s", s);
    getchar();
    int l = strlen(s);
    string ans = base[l];
    for (int i = 0; i < l; i++) ans[ans.size() - i - 1] = s[l - i - 1];
    int res = to_int(ans), from = to_int(base[l]);
    while (res < from) res += po[l];
    cout << res << '\n';
  }
  return 0;
}
