#include <bits/stdc++.h>
using namespace std;
int n;
string s;
void solve() {
  cin >> s;
  int len = (int)s.size();
  long long minyear = 1989;
  long long ans = 0;
  long long p = 1;
  for (int i = len - 1; i >= 4; --i) {
    ans -= p * ((ans / p) % 10);
    ans += p * (s[i] - '0');
    p *= 10;
    while (ans < minyear) {
      ans += p;
    }
    minyear = ans + 1;
  }
  cout << ans << endl;
}
int main() {
  cin >> n;
  while (n--) solve();
  return 0;
}
