#include <bits/stdc++.h>
using namespace std;
long long int find(string x) {
  int abbr = stoi(x);
  if (x.size() == 1) {
    if (abbr == 9)
      return 1989;
    else
      return 1990 + abbr;
  } else if (x.size() == 2) {
    if (abbr == 99)
      return 1999;
    else
      return 2000 + abbr;
  } else if (x.size() == 3) {
    if (abbr >= 99)
      return 2000 + abbr;
    else
      return 3000 + abbr;
  } else if (x.size() == 4) {
    if (abbr >= 3099)
      return abbr;
    else
      return 10000 + abbr;
  } else if (x.size() == 5) {
    if (abbr >= 13099)
      return abbr;
    else
      return 100000 + abbr;
  } else if (x.size() == 6) {
    if (abbr >= 113099)
      return abbr;
    else
      return 1e6 + abbr;
  } else if (x.size() == 7) {
    if (abbr >= 1113099)
      return abbr;
    else
      return 1e7 + abbr;
  } else if (x.size() == 8) {
    if (abbr >= 11113099)
      return abbr;
    else
      return 1e8 + abbr;
  } else {
    if (abbr >= 111113099)
      return abbr;
    else
      return 1e9 + abbr;
  }
}
int main() {
  string s, abbr;
  int n, i, j, k, l, ans;
  cin >> n;
  while (n--) {
    cin >> s;
    l = s.find("'");
    abbr = s.substr(l + 1);
    cout << find(abbr) << "\n";
  }
  return 0;
}
