#include <bits/stdc++.h>
using namespace std;
int n;
char buf[1002];
string s;
int t;
vector<long long int> v;
int main() {
  cin >> t;
  while (t--) {
    v.clear();
    scanf("%s", buf);
    s = buf;
    long long int n = 0;
    long long int base = 1LL;
    for (int i = s.size() - 1; i >= 4; i--) {
      n += (long long int)(s[i] - '0') * base;
      base *= 10LL;
      v.push_back(n);
    }
    long long int NUM = 1988LL;
    long long int add = 10LL;
    for (int i = 0; i < v.size(); i++) {
      if (NUM < v[i]) {
        NUM = v[i];
      } else {
        long long int D = NUM % add;
        if (D < v[i]) {
          NUM /= add;
          NUM *= add;
          NUM += v[i];
        } else {
          NUM /= add;
          NUM++;
          NUM *= add;
          NUM += v[i];
        }
      }
      add *= 10LL;
    }
    printf("%lld\n", NUM);
  }
  return 0;
}
