#include <bits/stdc++.h>
using namespace std;
int n, len;
string s, k;
int main() {
  scanf("%d", &n);
  while (n--) {
    cin >> s;
    len = s.size() - 4;
    k = s.substr(4, len);
    if (len == 1) {
      if (k == "9")
        printf("%d\n", 1989);
      else
        cout << "199" + k << endl;
    } else if (len == 2) {
      if (k == "99")
        printf("%d\n", 1999);
      else
        cout << "20" + k << endl;
    } else if (len == 3) {
      if (k < "099")
        cout << "3" + k << endl;
      else
        cout << "2" + k << endl;
    } else if (len == 4) {
      if (k >= "3099")
        cout << k << endl;
      else
        cout << "1" + k << endl;
    } else if (len == 5) {
      if (k >= "13099")
        cout << k << endl;
      else
        cout << "1" + k << endl;
    } else if (len == 6) {
      if (k >= "113099")
        cout << k << endl;
      else
        cout << "1" + k << endl;
    } else if (len == 7) {
      if (k >= "1113099")
        cout << k << endl;
      else
        cout << "1" + k << endl;
    } else if (len == 8) {
      if (k >= "11113099")
        cout << k << endl;
      else
        cout << "1" + k << endl;
    } else {
      if (k >= "111113099")
        cout << k << endl;
      else
        cout << "1" + k << endl;
    }
  }
  return 0;
}
