#include <bits/stdc++.h>
using namespace std;
int n;
long long ab[11], y[11];
long long val(string abv) {
  long long res = 0;
  for (int i = 0; i < (int)abv.size(); i++)
    res = 10 * res + ((long long)(abv[i] - '0'));
  return res;
}
int main() {
  cin.sync_with_stdio(false);
  long long p10 = 10;
  long long nb = 1989;
  for (int i = 0; i < (int)10; i++) {
    ab[i] = nb % p10;
    y[i] = nb;
    nb += p10;
    p10 *= ((long long)10);
  }
  cin >> n;
  while (n--) {
    char c;
    string abv;
    for (int i = 0; i < (int)4; i++) cin >> c;
    cin >> abv;
    long long k = val(abv);
    int l = abv.size() - 1;
    if (ab[l] <= k)
      printf("%I64d\n", y[l] + k - ab[l]);
    else
      printf("%I64d\n", y[l + 1] - (ab[l] - k));
  }
  return 0;
}
