#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline bool checkBit(long long n, int i) { return n & (1LL << i); }
inline long long setBit(long long n, int i) {
  return n | (1LL << i);
  ;
}
inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }
char a[1000], b[1000];
int main() {
  int t;
  long long n;
  scanf("%d", &t);
  while (t--) {
    scanf("%s", a);
    sscanf(a, "IAO'%s", b);
    int cnt = strlen(b);
    n = 0;
    for (int i = 0; i < cnt; ++i) n = n * 10LL + b[i] - '0';
    if (cnt == 1) {
      for (long long i = 0;; ++i) {
        long long m = i * 10 + n;
        if (1989 <= m && m <= 1998) {
          printf("%lld\n", m);
          break;
        }
      }
    } else if (cnt == 2) {
      for (long long i = 0;; ++i) {
        long long m = i * 100 + n;
        if (1999 <= m && m <= 2098) {
          printf("%lld\n", m);
          break;
        }
      }
    } else if (cnt == 3) {
      for (long long i = 0;; ++i) {
        long long m = i * 1000 + n;
        if (2099 <= m && m <= 3098) {
          printf("%lld\n", m);
          break;
        }
      }
    } else if (cnt == 4) {
      for (long long i = 0;; ++i) {
        long long m = i * 10000 + n;
        if (3099 <= m && m <= 13098) {
          printf("%lld\n", m);
          break;
        }
      }
    } else if (cnt == 5) {
      for (long long i = 0;; ++i) {
        long long m = i * 100000 + n;
        if (13099 <= m && m <= 113098) {
          printf("%lld\n", m);
          break;
        }
      }
    } else if (cnt == 6) {
      for (long long i = 0;; ++i) {
        long long m = i * 1000000 + n;
        if (113099 <= m && m <= 1113098) {
          printf("%lld\n", m);
          break;
        }
      }
    } else if (cnt == 7) {
      for (long long i = 0;; ++i) {
        long long m = i * 10000000 + n;
        if (1113099 <= m && m <= 11113098) {
          printf("%lld\n", m);
          break;
        }
      }
    } else if (cnt == 8) {
      for (long long i = 0;; ++i) {
        long long m = i * 100000000 + n;
        if (11113099 <= m && m <= 111113098) {
          printf("%lld\n", m);
          break;
        }
      }
    } else if (cnt == 9) {
      for (long long i = 0;; ++i) {
        long long m = i * 1000000000 + n;
        if (111113099 <= m && m <= 1111113098) {
          printf("%lld\n", m);
          break;
        }
      }
    }
  }
  return 0;
}
