#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
long long mod = 1000000007LL;
long long mod2 = 998244353LL;
int t, n;
int k;
long long bn[20], pw[20];
int main() {
  pw[0] = 1LL;
  for (int i = 1; i <= 10; ++i) {
    pw[i] = pw[i - 1] * 10LL;
  }
  bn[1] = 1989;
  for (int i = 2; i <= 10; ++i) {
    bn[i] = bn[i - 1] + pw[i - 1];
  }
  cin >> n;
  while (n-- > 0) {
    string s;
    cin >> s;
    s = s.substr(4);
    int len = s.size();
    long long x = stol(s);
    long long sfx = bn[len] % pw[len];
    long long det = (x - sfx + pw[len]) % pw[len];
    printf("%lld\n", bn[len] + det);
  }
  return 0;
}
