#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  int n;
  cin >> n;
  vector<string> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  for (string g : v) {
    string x = g.substr(4);
    set<long long> s;
    long long ans;
    for (int i = x.size() - 1; i >= 0; --i) {
      long long v = stoi((x.substr(i)).c_str());
      long long t = 1;
      for (int k = x.size() - 1; k >= i; --k) t *= 10;
      while (v < 1989 || s.count(v)) v += t;
      s.insert(v);
      ans = v;
    }
    cout << ans << endl;
  }
  return 0;
}
