#include <bits/stdc++.h>
using namespace std;
string its(int x) {
  string r = "";
  while (x > 0) {
    r += x % 10 + 48;
    x /= 10;
  }
  return r;
}
string anw(string x) {
  if (x.size() == 1) {
    if (x[0] == '9')
      return "1989";
    else
      return "199" + x;
  }
  if (x.size() == 2) {
    if (x == "99")
      return "1999";
    else
      return "20" + x;
  }
  if (x.size() == 3) {
    if (x == "099") return "2099";
    if (x < "099")
      return "3" + x;
    else
      return "2" + x;
  }
  if (x.size() == 4) {
    if (x < "3099")
      return "1" + x;
    else
      return x;
  }
  if (x.size() == 5) {
    if (x < "13099")
      return "1" + x;
    else
      return x;
  }
  if (x.size() == 6) {
    if (x < "113099")
      return "1" + x;
    else
      return x;
  }
  if (x.size() == 7) {
    if (x < "1113099")
      return "1" + x;
    else
      return x;
  }
  if (x.size() == 8) {
    if (x < "11113099")
      return "1" + x;
    else
      return x;
  }
  if (x.size() == 9) {
    if (x < "111113099")
      return "1" + x;
    else
      return x;
  }
  return "";
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string t;
    cin >> t;
    string a = t.substr(4);
    cout << anw(a) << endl;
  }
}
