#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  getline(cin, str);
  istringstream iss(str);
  int n;
  iss >> n;
  vector<long long int> c(11, 0);
  for (int i = 1; i < 11; ++i) c[i] = c[i - 1] * 10 + 10;
  for (int i = 0; i < n; ++i) {
    getline(cin, str);
    string numstr = str.substr(str.find('\'') + 1);
    istringstream iss(numstr);
    long long int num;
    iss >> num;
    int k = int(numstr.size());
    long long int p10 = 1;
    for (int j = 0; j < k; ++j) p10 *= 10;
    while (num < 1989 + c[k - 1]) {
      num += p10;
    }
    cout << num << endl;
  }
  return 0;
}
