#include <bits/stdc++.h>
using namespace std;
template <class T>
using us = unordered_set<T>;
template <class T>
using vec = vector<T>;
const long long infll = numeric_limits<long long>::max() >> 1;
const int inf = numeric_limits<int>::max() >> 1;
const int N = 1001;
int n;
int ten[N];
void input() {
  cin >> n;
  ten[0] = 1;
  for (int i = 1; i < 10; ++i) {
    ten[i] = ten[i - 1] * 10;
  }
}
void solve() {
  for (int i = 0; i < n; ++i) {
    string t;
    cin >> t;
    string sl;
    t = t.substr(4);
    int l = 1989 + (ten[(int)t.size()] - 1) / 9 - 1;
    sl = to_string(l);
    for (int j = 0; j < N; ++j) {
      string s = to_string(j) + t;
      if (!j) {
        s = s.substr(1);
      }
      if ((int)s.size() < (int)sl.size() ||
          (int)s.size() == (int)sl.size() && s < sl) {
        continue;
      }
      cout << s << "\n";
      break;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  input();
  solve();
}
