#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool getmin(T *a, const T &b) {
  if (b < *a) {
    *a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool getmax(T *a, const T &b) {
  if (b > *a) {
    *a = b;
    return true;
  }
  return false;
}
template <class T>
inline void read(T *a) {
  char c;
  while (isspace(c = getchar())) {
  }
  bool flag = 0;
  if (c == '-')
    flag = 1, *a = 0;
  else
    *a = c - 48;
  while (isdigit(c = getchar())) *a = *a * 10 + c - 48;
  if (flag) *a = -*a;
}
const int mo = 1000000007;
template <class T>
T pow(T a, T b, int c = mo) {
  T res = 1;
  for (T i = 1; i <= b; i <<= 1, a = 1LL * a * a % c)
    if (b & i) res = 1LL * res * a % c;
  return res;
}
set<string> S;
map<string, int> ans;
string zhuan(int x) {
  int a[10];
  int n = 0;
  while (x) a[++n] = x % 10, x /= 10;
  string s = "";
  string empty = "";
  for (int i = (1); i <= (n); ++i) {
    s = empty + char('0' + a[i]) + s;
    if (S.find(s) == S.end()) {
      S.insert(s);
      return s;
    }
  }
}
int n;
const int x[] = {3099, 13099, 113099, 1113099, 11113099, 111113099};
int main() {
  for (int i = (1989); i <= (13110); ++i) {
    string s = zhuan(i);
    ans[s] = i;
  }
  scanf("%d\n", &n);
  while (n--) {
    char c[20];
    scanf("IAO'%s\n", c);
    string s;
    s.assign(c);
    if (ans.find(s) != ans.end()) {
      cout << ans[s] << endl;
      continue;
    }
    string one = "1";
    for (int i = (0); i <= (5); ++i) {
      if (s.size() == i + 4) {
        if (strtol(c, NULL, 10) < x[i])
          cout << one + s << endl;
        else
          cout << s << endl;
        break;
      }
    }
  }
  return 0;
}
