#include <bits/stdc++.h>
using namespace std;
string save[10100];
string another[10100];
map<string, int> cao;
int main(int argc, const char* argv[]) {
  for (int i = 1989; i < 10000; i++) {
    string tmp = "";
    char str[10];
    int cnt = 0;
    int ti = i;
    while (ti) {
      str[cnt++] = ti % 10 + '0';
      ti /= 10;
    }
    for (int j = 0; j < cnt; j++) {
      string tmp1 = "";
      tmp1 += str[j];
      tmp1 += tmp;
      tmp = tmp1;
      if (cao[tmp] == 0) {
        cao[tmp] = 1;
        break;
      }
    }
    save[i] = tmp;
  }
  int numa = 0;
  for (int i = '0'; i <= '9'; i++) {
    for (int i1 = '0'; i1 <= '9'; i1++)
      for (int i2 = '0'; i2 <= '9'; i2++)
        for (int i3 = '0'; i3 <= '9'; i3++) {
          string tmp = "";
          tmp += i;
          tmp += i1;
          tmp += i2;
          tmp += i3;
          if (cao[tmp] == 0) {
            another[numa++] = tmp;
          }
        }
  }
  int T;
  cin >> T;
  while (T--) {
    char str[110];
    scanf("%s", str);
    int i = 0;
    while (str[i] != '\'') {
      i++;
    }
    int ti = i + 1;
    string tmp;
    i++;
    while (str[i] != '\0') {
      tmp += str[i];
      i++;
    }
    int flag = 0;
    for (i = 1989; i < 10000; i++) {
      if (save[i] == tmp) {
        flag = i;
        break;
      }
    }
    if (flag != 0) {
      printf("%d\n", flag);
      continue;
    }
    if (str[ti] == '0') {
      cout << "1" << tmp << endl;
      continue;
    }
    int len = tmp.length();
    string tmp1 = "";
    for (i = len - 4; i < len; i++) {
      tmp1 += tmp[i];
    }
    flag = 0;
    for (i = 0; i < numa; i++) {
      if (another[i] == tmp1) {
        flag = 1;
        break;
      }
    }
    for (i = len - 5; i >= 0; i--) {
      char cc = tmp[i];
      if (cc == '0')
        flag = 1;
      else {
        if (cc != '1') {
          flag = 0;
        }
      }
    }
    if (flag == 0) {
      cout << tmp << endl;
    } else {
      cout << "1" << tmp << endl;
    }
  }
  return 0;
}
