#include <bits/stdc++.h>
using namespace std;
long long n, p, l, res, aux, t;
string s;
map<string, long long> m;
bool nueves;
int main() {
  cin >> n;
  while (n--) {
    cin >> s;
    t = 0;
    if (m.find(s) == m.end()) {
      p = 1;
      l = s.size();
      res = 1989;
      while (l - 4 > t + 1) {
        p *= 10;
        res += p;
        t++;
      }
      nueves = true;
      aux = 0;
      for (int i = 4; i < l; i++) {
        aux *= 10;
        aux += s[i] - '0';
      }
      p *= 10;
      if (aux < res % p) {
        res += p;
        res /= p;
        res *= p;
        res += aux;
      } else {
        res /= p;
        res *= p;
        res += aux;
      }
      m[s] = res;
    }
    cout << m[s] << endl;
  }
  return 0;
}
