#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
long long pw[15];
long long getNext(string s, long long from) {
  set<long long> was;
  long long add = atoi(s.c_str());
  if (s[0] != '0' && add >= from) return add;
  for (int a = 1; a <= 999; ++a) {
    long long x = (long long)a * pw[s.size()] + add;
    if (x >= from) return x;
  }
}
int main() {
  pw[0] = 1;
  for (int i = 1; i < 15; ++i) {
    pw[i] = pw[i - 1] * 10LL;
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    s.erase(0, 4);
    long long cur = 1988;
    for (int j = s.size() - 1; j >= 0; --j) {
      string cs = s.substr(j, s.size() - j);
      cur = getNext(cs, cur + 1LL);
    }
    cout << cur << '\n';
  }
  return 0;
}
