#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
int compare(string r, string bs) {
  if ((int)(r.size()) > (int)(bs.size()) and r[0] > '0') return 1;
  if ((int)(r.size()) < (int)(bs.size())) return 0;
  for (int i = 0; i < (int)(r.size()); i++) {
    if (r[i] < bs[i])
      return 0;
    else if (r[i] > bs[i])
      return 1;
  }
  return 1;
}
string ss, s;
int ten[10] = {1,      10,      100,      1000,      10000,
               100000, 1000000, 10000000, 100000000, 1000000000};
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ss;
    string s = "";
    for (int j = 4; j < (int)(ss.size()); j++) {
      s = s + ss[j];
    }
    int base = 1989;
    for (int j = 1; j < (int)(s.size()); j++) {
      base += ten[j];
    }
    string bs = to_string(base);
    if (compare(s, bs)) {
      cout << s << endl;
      continue;
    }
    for (int j = 1; j <= 1000; j++) {
      string r = to_string(j) + s;
      if (compare(r, bs) and (int)(r.size()) >= (int)(bs.size())) {
        cout << r << endl;
        break;
      }
    }
  }
  return 0;
}
