#include <bits/stdc++.h>
using namespace std;
long long f(string x, long long y) {
  if (x.length() == 1) {
    while (y % 10 != x[0] - '0') ++y;
    return y;
  } else {
    long long w = 1;
    for (int i = 0; i < x.length(); ++i) w *= 10;
    long long z = f(x.substr(1), y);
    long long xx = atoll(x.c_str());
    return (z + 1 - xx + w - 1) / w * w + xx;
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    cout << f(s.substr(4), 1989) << endl;
  }
}
