#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e6 + 100;
const int mod = 1e9 + 7;
const int inf = 1e9;
long long n;
string s;
long long get() {
  long long res = 0;
  for (long long i = (4); i <= (((int)s.size()) - 1); i++) {
    res = res * 10 + (s[i] - 48);
  }
  return res;
}
int main() {
  ios ::sync_with_stdio(false);
  cin >> n;
  while (n--) {
    cin >> s;
    long long k = ((int)s.size()) - 4, year = get(), F = 0, POW = 10;
    for (long long i = (1); i <= (k - 1); i++) {
      F += POW;
      POW *= 10;
    }
    while (year < 1989 + F) year += POW;
    cout << year << endl;
  }
  return 0;
}
