#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "{" << p.first << "," << p.second << "}";
  return os;
}
const int N = 3e5 + 5;
const int oo = 1e9 + 7;
string plas_one(string s) {
  int jog = 1;
  for (char &c : s) {
    jog += (c - '0');
    c = '0' + jog % 10;
    jog /= 10;
  }
  if (jog) s.push_back(jog + '0');
  return s;
}
bool isboro(string a, string b) {
  if (a.size() > b.size()) return 1;
  if (a.size() < b.size()) return 0;
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  return a > b;
}
string nxt(string choto, string pattern) {
  if (pattern.size() > choto.size()) {
    if (pattern.back() == '0') pattern.push_back('1');
    return pattern;
  }
  string ex = choto.substr(pattern.size());
  if (isboro(pattern + ex, choto)) return pattern + ex;
  ex = plas_one(ex);
  if (isboro(pattern + ex, choto)) return pattern + ex;
  assert(0);
  return "";
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int T, cs = 0;
  cin >> T;
  while (T--) {
    string s;
    cin >> s;
    string Base = "1988";
    s = s.substr(4);
    reverse(s.begin(), s.end());
    reverse(Base.begin(), Base.end());
    for (int i = 0; i < s.size(); i++) {
      Base = nxt(Base, s.substr(0, i + 1));
    }
    reverse(Base.begin(), Base.end());
    cout << Base << "\n";
  }
}
