#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const int inf = INT_MAX;
const int nmax = 1e5 + 5;
const int mod = 1e9 + 7;
using namespace std;
int n, k, i, ans, p, tmp;
string s;
char c;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cerr.tie(0);
  cout.tie(0);
  cin >> n;
  while (n--) {
    cin >> c >> c >> c >> c >> s;
    k = s.size(), ans = i = 0, p = 10, tmp = 0;
    while (i < k) ans += (s[i] - '0'), ans *= 10, i++, tmp += p, p *= 10;
    p /= 10, tmp -= p, ans /= 10;
    while (ans < 1989 + tmp) ans += p;
    cout << ans << endl;
  }
  return 0;
}
