#include <bits/stdc++.h>
using namespace std;
const int maxn = 10005;
const int logn = 10;
const int inf = (int)2e9 + 5;
const long long mod = (int)1e9 + 7;
const long long base = 2204234849;
const long long l_inf = (long long)4e18;
const long double pi = acos(-1.0);
const long double eps = 1e-12;
int n;
string a[maxn];
map<string, long long> used;
vector<long long> good;
inline void process(long long x) {
  long long X = x;
  string y = "";
  y += char('0' + (x % 10));
  while (used[y]) {
    x /= 10;
    y += '0' + x % 10;
  }
  used[y] = X;
}
inline int len(long long x) {
  int cnt = 0;
  while (x) {
    x /= 10;
    cnt++;
  }
  return cnt;
}
inline long long value(string x) {
  long long y = 0;
  for (char c : x) {
    y = y * 10 + c - '0';
  }
  return y;
}
inline string get(string x) {
  if (x[0] == '0') return '1' + x;
  for (long long z : good) {
    if (len(z) != (int)x.size()) continue;
    if (value(x) < z) {
      return '1' + x;
    } else {
      return x;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(12);
  cout << fixed;
  srand(566);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] = a[i].substr(4, (int)a[i].size() - 4);
  }
  for (int i = 1989; i < 10000; i++) process(i);
  good.push_back(3099);
  long long d = 10000;
  for (int i = 1; i < 10; i++) {
    good.push_back(good[i - 1] + d);
    d *= 10;
  }
  for (int i = 0; i < n; i++) {
    if ((int)a[i].size() < 4) {
      reverse(a[i].begin(), a[i].end());
      cout << used[a[i]] << '\n';
    } else {
      cout << get(a[i]) << '\n';
    }
  }
  return 0;
}
