#include <bits/stdc++.h>
using namespace std;
int Pow10(int deg) {
  int res = 1;
  while (deg-- > 0) res *= 10;
  return res;
}
int ToInt(const string& from) {
  int res = 0;
  for (int i = 0; i < ((int)(from).size()); ++i) res = 10 * res + from[i] - '0';
  return res;
}
void Solve() {
  string buf;
  do {
    getline(cin, buf);
  } while (((int)(buf).size()) < 4);
  string year = buf.substr(4);
  int lo = 1988;
  for (int i = ((int)(year).size()) - 1; i >= 0; --i) {
    int add = Pow10(((int)(year).size()) - i);
    int base = lo / add;
    int rem = ToInt(year.substr(i));
    while (base * add + rem <= lo) ++base;
    lo = base * add + rem;
  }
  cout << lo << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  int q;
  cin >> q;
  while (q-- > 0) Solve();
  return 0;
}
