#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
template <typename T>
void chmin(T& a, const T& b) {
  if (b < a) a = b;
}
int N;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  vector<string> S(N);
  for (int i = (0); i < (N); i++) {
    cin >> S[i];
    S[i] = S[i].substr(4);
  }
  for (int i = (0); i < (N); i++) {
    long long year = 1988, pow10 = 1;
    for (int j = (0); j < (S[i].size()); j++) {
      year += pow10;
      pow10 *= 10;
    }
    if (stoll(S[i]) < year % pow10) {
      year += pow10;
    }
    year += stoll(S[i]) - (year % pow10);
    cout << year << endl;
  }
  return 0;
}
