#include <bits/stdc++.h>
using namespace std;
long long power(int power) {
  long long ret = 1;
  for (int i = 0; i < power; i++) {
    ret = ret * 10;
  }
  return ret;
}
int numberOfDigits(long long x) {
  int ret = 0;
  while (x > 0) {
    x = x / 10;
    ret++;
  }
  return ret;
}
long long prefixForGreaterNumber(long long minNumber, long long suffix,
                                 int numberOfCharacters) {
  int digitsPresent = numberOfCharacters;
  int digitsWanted = numberOfDigits(minNumber);
  long long divisor = power(digitsPresent);
  long long foreword = minNumber / divisor;
  long long backword = minNumber % divisor;
  long long ret;
  if (backword < suffix) {
    ret = foreword * divisor + suffix;
  } else {
    ret = (foreword + 1) * divisor + suffix;
  }
  if (numberOfDigits(ret) < numberOfCharacters) {
    ret = power(numberOfCharacters) + suffix;
  }
  return ret;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string abr;
    cin >> abr;
    abr = abr.substr(4);
    long long number = stoll(abr, NULL, 10);
    int ret = prefixForGreaterNumber(1988, number % 10, 1);
    for (int j = 2; j <= abr.length(); j++) {
      ret = prefixForGreaterNumber(ret, number % (long long)power(j), j);
    }
    cout << ret << endl;
  }
}
