#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int maxn = 1005, maxm = 29;
const double eps = 1e-9;
const double pi = acos(-1.0);
int T;
char c[55];
int a[maxn];
int main() {
  int i, j, k;
  scanf("%d", &T);
  while (T--) {
    scanf("%s", c);
    int l = strlen(c);
    memset(a, 0, sizeof(a));
    a[2] = 9, a[3] = 1;
    for (i = 4; i < l; i++) c[i] -= '0';
    if (c[l - 1] == 9)
      a[0] = 9, a[1] = 8;
    else
      a[0] = c[l - 1], a[1] = 9;
    for (i = l - 2; i >= 4; i--) {
      if (c[i] > a[l - 1 - i])
        a[l - 1 - i] = c[i];
      else
        a[l - 1 - i] = c[i], ++a[l - i];
      for (j = l - i; j < maxn - 1; j++) {
        if (a[j] >= 10)
          a[j + 1] += a[j] / 10, a[j] %= 10;
        else
          break;
      }
    }
    long long r = 0;
    for (i = maxn - 1; i >= 0; i--) r = r * 10 + a[i];
    printf("%I64d\n", r);
  }
  return 0;
}
