#include <bits/stdc++.h>
using namespace std;
long long a[int(1e5 + 5)], si[int(1e5 + 5)], i, m, ans, k, l, j, q, x, n, ma,
    mi, X;
string s;
vector<int> vec[int(1e5 + 5)];
vector<int> get(vector<int> v, vector<int> g) {
  vector<int> ans;
  if (g.size() == 0) {
    ans.push_back(v[0]);
    if (v[0] == 9)
      ans.push_back(8);
    else
      ans.push_back(9);
    ans.push_back(9);
    ans.push_back(1);
    return ans;
  }
  if (v.size() > g.size())
    if (v.back() == 0) v.push_back(1);
  if (v.size() > g.size()) return v;
  if (v.size() == g.size()) {
    for (int i = v.size() - 1; i >= 0; i--) {
      if (v[i] > g[i]) return v;
      if (v[i] < g[i]) break;
    }
    v.push_back(1);
    return v;
  }
  int ravi = 0;
  for (int i = 0; i < v.size(); i++) {
    if (v[i] > g[i]) ravi = 1;
    if (v[i] < g[i]) ravi = -1;
  }
  int la = v.size();
  for (int i = v.size(); i < g.size(); i++) v.push_back(g[i]);
  if (ravi == -1 || ravi == 0) v[la]++;
  for (int i = la; i < g.size(); i++) {
    if (v[i] > 9) {
      v[i] -= 10;
      if (i == v.size() - 1) v.push_back(0);
      v[i + 1]++;
    }
  }
  if (v.back() == 0) v.push_back(1);
  return v;
}
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> s;
    s.erase(0, 4);
    for (int j = 0; j < s.size(); j++) {
      vec[i].push_back(s[j] - '0');
    }
  }
  vector<int> las;
  for (i = 0; i < n; i++) {
    vector<int> ne;
    las.clear();
    for (int p = vec[i].size() - 1; p >= 0; p--) {
      ne.push_back(vec[i][p]);
      las = get(ne, las);
    }
    if (las.back() == 0) las.push_back(1);
    for (int i = las.size() - 1; i >= 0; i--) cout << las[i];
    cout << endl;
  }
}
