#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int n, m;
string s;
vector<pair<string, string> > abbOrg;
void setOrg(string abb, string sup, int idx) {
  if (abb.length() > sup.length() ||
      (abb.length() == sup.length() && abb > sup)) {
    abbOrg[idx].second = (abb[0] == '0') ? "1" + abb : abb;
    return;
  } else {
    int diff = sup.length() - abb.length();
    if (diff == 0) {
      abbOrg[idx].second = "1" + abb;
      return;
    }
    abbOrg[idx].second = sup.substr(0, diff) + abb;
    if (sup[diff] >= abb[0]) {
      int idx1 = diff - 1;
      bool finish = 0;
      while (idx1 >= 0) {
        if (abbOrg[idx].second[idx1] == '9') {
          abbOrg[idx].second[idx1] = '0';
          idx1--;
        } else {
          abbOrg[idx].second[idx1] = abbOrg[idx].second[idx1] + 1;
          finish = 1;
          break;
        }
      }
      if (!finish) abbOrg[idx].second = "1" + abbOrg[idx].second;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < (int)n; i++) {
    abbOrg.clear();
    cin >> s;
    int pos = s.length();
    while (pos-- >= 5) {
      abbOrg.push_back(make_pair(s.substr(pos), ""));
    }
    abbOrg[0].second =
        (abbOrg[0].first >= "9") ? "1989" : "199" + abbOrg[0].first;
    for (int i = 1; i < (int)abbOrg.size(); i++) {
      setOrg(abbOrg[i].first, abbOrg[i - 1].second, i);
    }
    cout << abbOrg[abbOrg.size() - 1].second << "\n";
  }
  return 0;
}
