#include <bits/stdc++.h>
using namespace std;
long long solve(string s) {
  int n = s.size();
  if (n == 1) {
    if (s[0] == '9') {
      return 1980 + s[0] - '0';
    } else {
      return 1990 + s[0] - '0';
    }
  }
  long long sm = 0;
  long long p = 1;
  for (char c : s) {
    sm = sm * 10 + c - '0';
    p *= 10;
  }
  long long prev = solve(s.substr(1));
  ++prev;
  return (prev - sm + p - 1) / p * p + sm;
}
int f(int x) {
  ++x;
  return (x - 17 + 99) / 100 * 100 + 17;
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < int(n); ++i) {
    string s;
    cin >> s;
    cout << solve(s.substr(4)) << "\n";
  }
}
