#include <bits/stdc++.h>
const int INF = 1E9 + 7;
const long long INFLL = 1E17;
const double phi = 2 * acos(0);
const double EPS = 1E-9;
using namespace std;
int t;
char s[100];
int digit(long long a) {
  int ret = 0;
  while (a > 0) ret++, a = a / 10;
  return ret;
}
long long ten(int a) {
  long long ret = 1;
  while (a--) ret *= 10;
  return ret;
}
long long bil(long long ret, int len) {
  if (len == 0) return 1988;
  long long tt = ten(len);
  long long bts = bil(ret % ten(len - 1), len - 1);
  if (bts < 1989) bts = 1988;
  long long l = 0, r = INF;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (mid * tt + ret > bts)
      r = mid - 1;
    else
      l = mid + 1;
  }
  return l * tt + ret;
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%s", &s);
    int len = strlen(s);
    long long ret = 0;
    for (int k = 4; k < (int)len; k++) {
      ret *= 10;
      ret += s[k] - '0';
    }
    printf("%I64d\n", bil(ret, len - 4));
  }
  return 0;
}
