#include <bits/stdc++.h>
using namespace std;
int T, n;
string s;
int main() {
  cin >> T;
  while (T--) {
    int q = 0;
    cin >> s;
    s = s.substr(4);
    int l = s.size();
    for (int i = 0; i < l; i++) {
      q = q * 10 + s[i] - '0';
    }
    int tmp = 0;
    int ten = 10;
    for (int i = 1; i < l; i++) {
      tmp += ten;
      ten *= 10;
    }
    while (tmp + 1989 > q) {
      q += ten;
    }
    cout << q << endl;
  }
  return 0;
}
