#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int maxn = 1e7 + 10;
const int mod = 1000000007;
int n;
string s, ss;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    ss.clear();
    int pos = 0, len = s.size(), sum = 0;
    for (int j = 4; j < len; j++) sum = sum * 10 + s[j] - '0', ss += s[j];
    int dis = len - 4;
    if (dis == 1) {
      if (sum == 9)
        cout << "1989" << endl;
      else
        cout << "199" << ss << endl;
    } else if (dis == 2) {
      if (sum == 99)
        cout << "1999" << endl;
      else
        cout << "20" << ss << endl;
    } else if (dis == 3) {
      if (sum <= 98)
        cout << "3" << ss << endl;
      else
        cout << "2" << ss << endl;
    } else {
      int tmp = dis - 4, limit = 0;
      for (int j = 1; j <= tmp; j++) limit = limit * 10 + 1;
      limit = limit * 10000 + 3098;
      if (sum <= limit)
        cout << "1" << ss << endl;
      else
        cout << ss << endl;
    }
  }
  return 0;
}
