#include <bits/stdc++.h>
using namespace std;
const int N = 1234;
const int mod = 1000000007;
vector<string> val = {"1989",      "1999",       "2099",        "3099",
                      "13099",     "113099",     "1113099",     "11113099",
                      "111113099", "1111113099", "11111113099", "111111113099"};
char s[N];
int solve(int test) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s);
    string ss = "";
    int j = strlen(s) - 1;
    while (j >= 0 && s[j] >= '0' && s[j] <= '9') ss += s[j], j--;
    reverse(ss.begin(), ss.end());
    int nn = ss.size();
    nn--;
    if (nn == 0) {
      if (ss[0] == '9') {
        printf("1989\n");
      } else {
        printf("199%s\n", ss.c_str());
      }
      continue;
    }
    if (nn == 1) {
      int cur = atoi(ss.c_str());
      if (cur == 99) {
        printf("1999\n");
      } else {
        printf("20%s\n", ss.c_str());
      }
      continue;
    }
    if (nn == 2) {
      int cur = atoi(ss.c_str());
      if (cur < 99) {
        printf("3%s\n", ss.c_str());
      } else {
        printf("2%s\n", ss.c_str());
      }
      continue;
    }
    if (nn == 3) {
      int lo = atoi(val[nn].c_str());
      int hi = atoi(val[nn + 1].c_str());
      int cur = atoi(ss.c_str());
      if (cur < lo) {
        printf("1%s\n", ss.c_str());
      } else {
        printf("%s\n", ss.c_str());
      }
      continue;
    }
    long long cur = stoll(ss.c_str());
    long long lo = stoll(val[nn].c_str());
    long long hi = stoll(val[nn + 1].c_str());
    if (cur < lo) {
      printf("1%s\n", ss.c_str());
    } else {
      printf("%s\n", ss.c_str());
    }
  }
  return (0);
}
void allClear() {}
int main() {
  int t = 1;
  for (int _ = 1; _ <= t; ++_) {
    int ret = solve(_);
    allClear();
  }
  return (0);
}
