#include <bits/stdc++.h>
using namespace std;
string getNextOwner(string s, char c) {
  int n = s.length();
  if (n == 0) {
    string ans = "";
    if (c == '0') ans = "1";
    ans += c;
    return ans;
  }
  if (s[n - 1] < c) {
    string ans = "";
    ans = s.substr(0, n - 1);
    ans += c;
    return ans;
  }
  if (n == 1) {
    string ans = "1";
    ans += c;
    return ans;
  }
  int aux = stoi(s.substr(0, n - 1));
  aux++;
  string ans = to_string(aux);
  ans += c;
  return ans;
}
string getOwner(string s) {
  if (s == "9")
    return "198";
  else if (s.length() == 1)
    return "199";
  string owner = getOwner(s.substr(1));
  string nextOwner = getNextOwner(owner, s[0]);
  return nextOwner.substr(0, nextOwner.length() - 1);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    string abbr = s.substr(4);
    if (abbr.length() > 1) {
      string owner = getOwner(abbr);
      string ans = owner;
      ans += abbr;
      cout << stoi(ans) << endl;
    } else {
      if (abbr[0] == '9') {
        cout << "1989" << endl;
      } else {
        string ans = "199";
        ans += abbr[0];
        cout << ans << endl;
      }
    }
  }
  return 0;
}
