#include <bits/stdc++.h>
using namespace std;
const int STARTING_YEAR = 1988;
long long convertYearSuffixToYear(string yearSuffix) {
  long long yearFloor = STARTING_YEAR;
  int N = yearSuffix.length();
  long long p10 = 10;
  for (int i = N - 1; i >= 0; --i, p10 *= 10) {
    int yearSuffixSuffix = stoi(yearSuffix.substr(i));
    long long currentYear = yearSuffixSuffix;
    while (currentYear <= yearFloor) currentYear += p10;
    yearFloor = currentYear;
  }
  return yearFloor;
}
int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  for (int n = 0; n < N; ++n) {
    string abbreviation;
    cin >> abbreviation;
    string yearSuffix = abbreviation.substr(4);
    cout << convertYearSuffixToYear(yearSuffix) << '\n';
  }
  cout << flush;
  return 0;
}
