#include <bits/stdc++.h>
using namespace std;
string getAns(string x) {
  if (x.length() == 1) {
    if (x == "9") {
      return "198" + x;
    } else {
      return "199" + x;
    }
  }
  if (x.length() == 2) {
    if (x == "99") {
      return "19" + x;
    } else {
      return "20" + x;
    }
  }
  if (x.length() == 3) {
    if (x[0] == '0' && !(x[1] == '9' && x[2] == '9')) {
      return "3" + x;
    } else {
      return "2" + x;
    }
  }
  if (x.length() > 3) {
    bool isSmall = true, isVerySmall = false;
    for (int i = 0; i < x.length() - 4; i++) {
      if (x[i] > '1') {
        isSmall = false;
      }
      if (x[i] == '0') {
        isVerySmall |= isSmall;
      }
    }
    isSmall &= !(x[x.length() - 4] > '3' ||
                 x[x.length() - 4] == '3' && x[x.length() - 3] > '0' ||
                 x[x.length() - 4] == '3' && x[x.length() - 3] == '0' &&
                     x[x.length() - 2] == '9' && x[x.length() - 1] == '9');
    isSmall |= isVerySmall;
    if (!isSmall) {
      return x;
    } else {
      return "1" + x;
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    string x;
    scanf("\nIAO'");
    cin >> x;
    cout << getAns(x) << endl;
  }
  return 0;
}
