#include <bits/stdc++.h>
using namespace std;
map<string, long long> m;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  vector<pair<long long, long long> > v = {
      make_pair(1989, 1998),           make_pair(1999, 2098),
      make_pair(2099, 3098),           make_pair(3099, 13098),
      make_pair(13099, 113098),        make_pair(113099, 1113098),
      make_pair(1113099, 11113098),    make_pair(11113099, 111113098),
      make_pair(111113099, 1111113098)};
  for (int i = 1989; i <= 1998; i++) {
    string s = "";
    long long temp = i;
    s += (temp % 10 + 48);
    m[s] = i;
  }
  for (int i = 1999; i <= 2098; i++) {
    string s = "";
    long long temp = i;
    for (int j = 0; j < 2; j++) {
      s += (temp % 10 + 48);
      temp /= 10;
    }
    reverse(s.begin(), s.end());
    m[s] = i;
  }
  for (int i = 2099; i <= 3098; i++) {
    string s = "";
    long long temp = i;
    for (int j = 0; j < 3; j++) {
      s += (temp % 10 + 48);
      temp /= 10;
    }
    reverse(s.begin(), s.end());
    m[s] = i;
  }
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    string work = "";
    int sz = s.size();
    for (int j = 4; j < sz; j++) {
      work += s[j];
    }
    sz = work.size();
    if (sz <= 3) {
      cout << m[work] << "\n";
    } else {
      long long temp = v[sz - 1].first;
      string s1 = "";
      while (temp) {
        s1 += (temp % 10 + 48);
        temp /= 10;
      }
      reverse(s1.begin(), s1.end());
      if (work < s1) {
        cout << 1 << work << "\n";
      } else {
        cout << work << "\n";
      }
    }
  }
}
