#include <bits/stdc++.h>
using namespace std;
long long int number(long long int n) {
  if (n == 0) return 1;
  long long int i, k, l, c = 0;
  while (n > 0) {
    c++;
    n /= 10;
  }
  return c;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n, i, j, k, len, x, y, z, c, f, flag, p, q, mx, mn, l, r, sum,
      ans, tmp, it, pos, avg, m, cnt;
  long long int t;
  cin >> t;
  while (t--) {
    char ch;
    f = 0;
    flag = 0;
    ans = 0;
    cnt = 0;
    sum = 0;
    mn = LLONG_MAX;
    mx = LLONG_MIN;
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    s.pop_back();
    s.pop_back();
    s.pop_back();
    s.pop_back();
    reverse(s.begin(), s.end());
    x = 10;
    p = s.size();
    n = stoi(s);
    p--;
    for (i = 0; i < p; i++) {
      ans += x;
      x *= 10;
    }
    cnt = n;
    while (cnt < 1989 + ans) cnt += x;
    cout << cnt << "\n";
  }
  return 0;
}
