#include <bits/stdc++.h>
using namespace std;
string st;
int Q;
vector<int> a, A;
void go(int n) {
  bool B = false;
  while (n > A.size()) {
    A.push_back(0);
  }
  for (int i = n - 1; i >= 0; --i) {
    if (a[i] > A[i]) {
      B = true;
      break;
    }
    if (a[i] < A[i]) break;
  }
  for (int i = 0; i < n; ++i) A[i] = a[i];
  if (B == true) {
    return;
  }
  for (int i = n;; i++) {
    if (i == A.size()) {
      A.push_back(1);
      return;
    }
    if (A[i] < 9) {
      A[i]++;
      return;
    }
    A[i] = 0;
  }
  return;
}
int main() {
  cin >> Q;
  while (Q--) {
    cin >> st;
    a.clear();
    for (int i = 4; i < st.size(); i++) a.push_back(st[i] - '0');
    A.clear();
    A.resize(4);
    A[0] = 8;
    A[1] = 8;
    A[2] = 9;
    A[3] = 1;
    reverse(a.begin(), a.end());
    for (int i = 0; i < a.size(); ++i) {
      go(i + 1);
    }
    reverse(A.begin(), A.end());
    for (int i = 0; i < A.size(); ++i) cout << A[i];
    cout << endl;
  }
}
