#include <bits/stdc++.h>
using namespace std;
string s;
string cur;
string go;
void solve() {
  getline(cin, s);
  s = s.substr(4, 123123);
  cur = "1988";
  for (int i = 1; i <= (int)s.size(); i++) {
    go = cur;
    for (int j = 0; j < i; j++) {
      if ((int)go.size() - 1 - j < 0) {
        go = s[(int)s.size() - 1 - j] + go;
      } else {
        go[(int)go.size() - 1 - j] = s[(int)s.size() - 1 - j];
      }
    }
    if (go[0] == '0') {
      go = "1" + go;
    }
    if ((int)go.size() > (int)cur.size()) {
      cur = go;
      continue;
    }
    bool bigger = false;
    for (int j = 0; j < (int)go.size(); j++) {
      if (go[j] > cur[j]) {
        bigger = true;
        break;
      }
      if (go[j] < cur[j]) {
        break;
      }
    }
    if (bigger) {
      cur = go;
      continue;
    }
    int f = (int)go.size() - i;
    int can = -1;
    for (int j = f - 1; j >= 0; j--) {
      if (cur[j] < '9') {
        can = j;
        break;
      }
    }
    if (can == -1) {
      for (int j = 0; j < f; j++) {
        go[j] = '0';
      }
      go = "1" + go;
    } else {
      go[can] = cur[can] + 1;
      for (int j = can + 1; j < f; j++) {
        go[j] = '0';
      }
    }
    cur = go;
  }
  cout << cur << endl;
}
int main() {
  int tn;
  scanf("%d\n", &tn);
  while (tn--) {
    solve();
  }
  return 0;
}
