#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return {i, j};
}
struct printer {
  ~printer() { cerr << endl; }
  template <class c>
  printer& operator,(c x) {
    cerr << boolalpha << x;
    return *this;
  }
  printer& operator,(string x) {
    cerr << x;
    return *this;
  }
  template <class c, class d>
  printer& operator,(pair<c, d> x) {
    return *this, "(", x.first, ", ", x.second, ")";
  }
  template <class... d, template <class...> class c>
  printer& operator,(c<d...> x) {
    return *this, range(begin(x), end(x));
  }
  template <class c>
  printer& operator,(rge<c> x) {
    *this, "[";
    for (auto it = x.b; it != x.e; ++it) *this, (it == x.b ? "" : ", "), *it;
    return *this, "]";
  }
};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_rand(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); }
const int N = 100009;
long long ar[15];
void pre() {
  long long i, id = 1;
  for (i = 10; i <= 1e10; i = i * 10) {
    ar[id] = ar[id - 1] + i;
    id++;
  }
}
int main() {
  pre();
  int t;
  string s, second;
  cin >> t;
  while (t--) {
    long long sum = 1989, num = 0;
    cin >> s;
    int sz = s.size();
    int lastnum = sz - 4;
    for (int i = 4; i < sz; i++) {
      num = num * 10 + (s[i] - '0');
    }
    sum += ar[sz - 4 - 1];
    string st_sum = to_string(sum);
    int sz_sum = st_sum.size();
    long long sum1 = 0, sum2 = 0, flag = 0;
    for (int i = 0; i < sz_sum - lastnum; i++) {
      sum1 = sum1 * 10 + (st_sum[i] - '0');
    }
    for (int i = sz_sum - lastnum; i < sz_sum; i++) {
      sum2 = sum2 * 10 + (st_sum[i] - '0');
    }
    if (sum2 > num) flag = 1;
    sum1 += flag;
    if (sum1 > 0) {
      cout << sum1;
      for (int i = 4; i < sz; i++) cout << s[i];
      cout << '\n';
    } else
      cout << num << '\n';
  }
  return 0;
}
