#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
const int MAXN = 1e5 + 7;
int n;
string get_ans(string num) {
  int l = num.size();
  if (l == 1) {
    if (num == "9")
      return "1989";
    else
      return "199" + num;
  } else if (l == 2) {
    if (num == "99")
      return "1999";
    else
      return "20" + num;
  } else if (l == 3) {
    if (num == "099")
      return "2099";
    else if (num[0] == '0')
      return "3" + num;
    else
      return "2" + num;
  } else if (l == 4) {
    if (num >= "3099")
      return num;
    else
      return "1" + num;
  } else if (l == 5) {
    if (num >= "13099")
      return num;
    else
      return "1" + num;
  } else if (l == 6) {
    if (num >= "113099")
      return num;
    else
      return "1" + num;
  } else if (l == 7) {
    if (num >= "1113099")
      return num;
    else
      return "1" + num;
  } else if (l == 8) {
    if (num >= "11113099")
      return num;
    else
      return "1" + num;
  } else if (l == 9) {
    if (num >= "111113099")
      return num;
    else
      return "1" + num;
  }
  return "";
}
int main() {
  scanf("%d", &n);
  string s;
  for (int i = 0; i < n; ++i) {
    cin >> s;
    s = s.substr(4, s.size());
    cout << get_ans(s) << endl;
  }
  return 0;
}
