#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7, maxn = 100005, ln = 17;
const int shift = 30, etf = mod - 1;
const long long int inf = (long long int)1e18 + 1;
const double PI = (double)3.141592653589793238, EPSILON = 1e-10;
long long int syear[1005], cnt[1005];
void pre() {
  long long int x = 1989, mul = 1;
  for (int i = 1; i < 15; i++) {
    syear[i] = x;
    mul *= 10;
    cnt[i] = mul;
    x += mul;
  }
}
int main() {
  pre();
  int n;
  cin >> n;
  while (n--) {
    long long int ans;
    string s;
    cin >> s;
    int len = s.length() - 4;
    long long int num = 0;
    for (int i = 4; i < s.length(); i++) {
      num = num * 10 + s[i] - '0';
    }
    long long int st = syear[len] % cnt[len];
    if (num >= st) {
      ans = syear[len] - st + num;
    } else {
      ans = syear[len] - st + cnt[len] + num;
    }
    cout << ans << endl;
  }
  return 0;
}
