#include <bits/stdc++.h>
using namespace std;
long long int p10(long long int i) {
  long long int res = 1;
  for (int j = 0; j < int(i); j++) res *= 10;
  return res;
}
long long int digit(long long int n, long long int i) {
  for (int j = 0; j < int(i); j++) n /= 10;
  if (n == 0)
    return -1;
  else
    return n % 10;
}
long long int calc(string what) {
  long long int res = 1989;
  int N = int(what.size());
  for (int i = 0; i < int(N); i++) {
    int currentDigit = int(what[N - 1 - i] - '0');
    while (digit(res, i) != currentDigit) res += p10(i);
    if (i < N - 1) res += p10(i + 1);
  }
  return res;
}
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < int(N); i++) {
    char aux;
    cin >> aux >> aux >> aux >> aux;
    string what;
    cin >> what;
    cout << calc(what) << endl;
  }
  return 0;
}
