#include <bits/stdc++.h>
using namespace std;
string ans[] = {"1990", "1991", "1992", "1993", "1994",
                "1995", "1996", "1997", "1998", "1989"};
long long int pow(long long int a, long long int n) {
  long long int ret = 1;
  for (int i = 0; i < n; i++) {
    ret *= a;
  }
  return ret;
}
string solve(string a) {
  if (a.size() == 1) return ans[a[0] - '0'];
  string min = solve(a.substr(1, a.size() - 1));
  long long int n = min.size();
  long long int increment = pow(10, a.size());
  long long int start = stoll(min);
  long long int cur = stoll(a);
  if (cur > start) return a;
  min[n - a.size()] = a[0];
  cur = stoll(min);
  while (cur <= start) {
    cur += increment;
  }
  return to_string(cur);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string temp;
    cin >> temp;
    temp = temp.substr(4, temp.size() - 4);
    cout << solve(temp) << '\n';
  }
}
