#include <bits/stdc++.h>
using namespace std;
template <class T>
using vv = vector<vector<T>>;
template <class T>
ostream &operator<<(ostream &os, const vector<T> &t) {
  os << "{";
  for (int(i) = 0; (i) < (t.size()); ++(i)) {
    os << t[i] << ",";
  }
  os << "}" << endl;
  return os;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &t) {
  return os << "(" << t.first << "," << t.second << ")";
}
template <class T>
inline bool MX(T &l, const T &r) {
  return l < r ? l = r, 1 : 0;
}
template <class T>
inline bool MN(T &l, const T &r) {
  return l > r ? l = r, 1 : 0;
}
const long long MOD = 1e9 + 7;
int main() {
  cout << fixed << setprecision(0);
  int T;
  cin >> T;
  vector<long long> hoge = {0};
  vector<long long> ten = {1};
  for (int(i) = 0; (i) < (9); ++(i)) hoge.push_back(hoge.back() * 10 + 1);
  for (int(i) = 0; (i) < (9); ++(i)) ten.push_back(ten.back() * 10);
  while (T--) {
    string str;
    cin >> str;
    str = str.substr(4);
    stringstream ss;
    ss << str;
    long long n;
    ss >> n;
    if (str.size() >= 4) {
      long long x = hoge[str.size() - 4] * 10000 + 3099;
      (n += ten[str.size()] - x) %= ten[str.size()];
      cout << x + n << endl;
    } else if (str.size() == 3) {
      (n += 1000 - 99) %= 1000;
      cout << 2099 + n << endl;
    } else if (str.size() == 2) {
      (n += 100 - 99) %= 100;
      cout << 1999 + n << endl;
    } else {
      (n += 10 - 9) %= 10;
      cout << 1989 + n << endl;
    }
  }
  return 0;
}
