#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  long long int k;
  string::size_type sz;
  for (int i = 0; i < n; i++) {
    cin >> s;
    s = s.substr(4, s.length() - 4);
    k = stoi(s, &sz);
    if (s.size() == 1) {
      if (k < 9) {
        cout << 199 << k << endl;
      } else {
        cout << 1989 << endl;
      }
    } else if (s.size() == 2) {
      if (k < 99) {
        cout << 20 << s << endl;
      } else {
        cout << 1999 << endl;
      }
    } else if (s.size() == 3) {
      if (k < 99) {
        cout << 3 << s << endl;
      } else if (k == 99) {
        cout << 2099 << endl;
      } else if (k > 99) {
        cout << 2 << k << endl;
      }
    } else if (s.size() == 4) {
      if (k < 3099) {
        cout << 1 << s << endl;
      } else {
        cout << s << endl;
      }
    } else if (s.size() == 5) {
      if (k < 13099) {
        cout << 1 << s << endl;
      } else {
        cout << s << endl;
      }
    } else if (s.size() == 6) {
      if (k < 113099) {
        cout << 1 << s << endl;
      } else {
        cout << s << endl;
      }
    } else if (s.size() == 7) {
      if (k < 1113099) {
        cout << 1 << s << endl;
      } else {
        cout << s << endl;
      }
    } else if (s.size() == 8) {
      if (k < 11113099) {
        cout << 1 << s << endl;
      } else {
        cout << s << endl;
      }
    } else if (s.size() == 9) {
      if (k < 111113099) {
        cout << 1 << s << endl;
      } else {
        cout << s << endl;
      }
    }
  }
  return 0;
}
