#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1.0);
const int MAXN = 300001;
vector<int> e1[MAXN];
vector<int> e2[MAXN];
int tp[MAXN];
bool ok = true;
vector<int> c[3];
vector<int> cur;
vector<int> av;
void dfs(int v, int cl) {
  if (tp[v] == 3 - cl) {
    ok = false;
    return;
  }
  if (tp[v] == cl) return;
  c[cl].push_back(v);
  tp[v] = cl;
  for (int i = 0; i < e1[v].size(); i++) {
    dfs(e1[v][i], cl);
  }
  for (int i = 0; i < e2[v].size(); i++) {
    dfs(e2[v][i], 3 - cl);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int cnt;
  string s;
  cin >> cnt;
  for (int i = 0; i < cnt; i++) {
    cin >> s;
    s = s.substr(4, s.length() - 4);
    long long a = 1988, s10 = 1, cur = 0;
    for (int i = s.length() - 1; i >= 0; i--) {
      a++;
      cur = cur + s10 * (long long)(s[i] - '0');
      s10 *= 10ll;
      if (a % s10 <= cur) {
        a = ((a / s10) * s10) + cur;
      } else {
        a = ((a / s10 + 1) * s10) + cur;
      }
    }
    cout << a << endl;
  }
  return 0;
}
