#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void check_min(T& a, T b) {
  if (b < a) a = b;
}
template <class T>
inline void check_max(T& a, T b) {
  if (a < b) a = b;
}
long long mp[][3] = {
    0,          0,           0,    8,           1990,         1980,
    98,         2000,        1900, 98,          3000,         2000,
    3098,       10000,       0,    13098,       100000,       0,
    113098,     1000000,     0,    1113098,     10000000LL,   0,
    11113098LL, 100000000LL, 0,    111113098LL, 1000000000LL, 0,
};
long long solve() {
  string s;
  cin >> s;
  while (!isdigit(s[0])) s.erase(s.begin());
  stringstream ss(s);
  long long n;
  ss >> n;
  return n + mp[int((s).size())][n <= mp[int((s).size())][0] ? 1 : 2];
}
int main() {
  std::ios_base::sync_with_stdio(false);
  int n_case;
  cin >> n_case;
  for (int index = 1; index <= n_case; ++index) {
    printf("%lld\n", solve());
  }
  return 0;
}
