#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i;
  cin >> n;
  string s[n];
  for (i = 0; i < n; i++) cin >> s[i];
  string test[15];
  test[1] = "9";
  test[2] = "99";
  test[3] = "099";
  test[4] = "3099";
  test[5] = "13099";
  test[6] = "113099";
  test[7] = "1113099";
  test[8] = "11113099";
  test[9] = "111113099";
  test[10] = "1111113099";
  for (i = 0; i < n; i++) {
    s[i] = s[i].substr(4, s[i].length() - 4);
  }
  for (i = 0; i < n; i++) {
    if (s[i].length() == 1) {
      if (s[i] < test[1])
        cout << "199";
      else
        cout << "198";
      cout << s[i] << endl;
    } else if (s[i].length() == 2) {
      if (s[i] < test[2])
        cout << "20";
      else
        cout << "19";
      cout << s[i] << endl;
    } else if (s[i].length() == 3) {
      if (s[i] < test[3])
        cout << "3";
      else
        cout << "2";
      cout << s[i] << endl;
    } else if (s[i].length() == 4) {
      if (s[i] < test[4]) cout << "1";
      cout << s[i] << endl;
    } else if (s[i].length() == 5) {
      if (s[i] < test[5]) cout << "1";
      cout << s[i] << endl;
    } else if (s[i].length() == 6) {
      if (s[i] < test[6]) cout << "1";
      cout << s[i] << endl;
    } else if (s[i].length() == 7) {
      if (s[i] < test[7]) cout << "1";
      cout << s[i] << endl;
    } else if (s[i].length() == 8) {
      if (s[i] < test[8]) cout << "1";
      cout << s[i] << endl;
    } else if (s[i].length() == 9) {
      if (s[i] < test[9]) cout << "1";
      cout << s[i] << endl;
    } else if (s[i].length() == 10) {
      if (s[i] < test[10]) cout << "1";
      cout << s[i] << endl;
    }
  }
  return 0;
}
