#include <bits/stdc++.h>
using namespace std;
long long L[20];
long long p10[20];
long long toll(const string& str) {
  long long rtn = 0;
  for (char ch : str) {
    rtn = rtn * 10 + (int)(ch - '0');
  }
  return rtn;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  L[1] = 1989;
  long long pw = 10;
  for (int i = 2; i <= 10; i++) {
    L[i] = L[i - 1] + pw;
    pw *= 10;
  }
  p10[0] = 1;
  for (int i = 1; i <= 10; i++) p10[i] = p10[i - 1] * 10;
  int Q;
  cin >> Q;
  string str;
  for (int q = 1; q <= Q; q++) {
    cin >> str;
    str = string(str.begin() + 4, str.end());
    int ln = (int)(str.size());
    long long now = toll(str);
    while (now < L[ln]) now += p10[ln];
    cout << now << '\n';
  }
  return 0;
}
