#include <bits/stdc++.h>
using namespace std;
template <class T>
int getbit(int i, T X) {
  return (X & (1 << (i - 1)));
}
template <class T>
T onbit(int i, T X) {
  return (X | (1 << (i - 1)));
}
template <class T>
T offbit(int i, T X) {
  return (X | (1 << (i - 1)) - (1 << (i - 1)));
}
template <class T>
T sqr(T x) {
  return (x * x);
}
template <class T>
T cube(T x) {
  return (x * x * x);
}
template <class T>
T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
int csx[4] = {0, 0, -1, 1};
int csy[4] = {-1, 1, 0, 0};
const int MOD = 1000000007;
const int inf = 1e9;
const long long linf = 1e18;
const int maxn = 2e5 + 5;
int c[] = {1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1989};
string n;
int Size(long long n) {
  int ans = 0;
  do {
    ans++;
    n /= 10;
  } while (n > 0);
  return ans;
}
long long power(int k) {
  long long ans = 1;
  for (int i = 1; i <= k; i++) ans *= 10;
  return ans;
}
int getNumber(long long g, int k) {
  int cnt = Size(g);
  do {
    int nb = g % 10;
    g /= 10;
    if (cnt == k) return nb;
    cnt--;
  } while (g > 0);
}
long long f(string nb) {
  int sz = nb.size();
  if (sz == 1) return (c[nb[0] - '0']);
  int x = nb[0] - '0';
  int y;
  long long g = f(nb.substr(1, nb.size() - 1));
  if (Size(g) - sz + 1 < 1)
    y = 0;
  else
    y = getNumber(g, Size(g) - sz + 1);
  if (x <= y) x += 10;
  return (g + (x - y) * power(sz - 1));
}
int main() {
  int test;
  cin >> test;
  for (int t = 1; t <= test; t++) {
    cin >> n;
    n.erase(0, 4);
    cout << f(n) << endl;
  }
  return 0;
}
