#include <bits/stdc++.h>
using namespace std;
const int maxn = 10010;
char str[maxn];
int main() {
  int t, i, j, k;
  scanf("%d", &t);
  while (t--) {
    scanf("%s", str);
    long long sum = 0, cnt = 0, len = strlen(str);
    for (i = 0; i < len; ++i) {
      if (str[i] >= '0' && str[i] <= '9') {
        sum = sum * 10 + (str[i] - '0');
        cnt++;
      }
    }
    if (cnt == 1) {
      if (sum == 9)
        printf("198%lld\n", sum);
      else
        printf("199%lld\n", sum);
    } else if (cnt == 2) {
      if (sum == 99) {
        printf("1999\n");
      } else
        printf("20%02lld\n", sum);
    } else if (cnt == 3) {
      if (sum >= 99) {
        printf("2%03lld\n", sum);
      } else {
        printf("3%03lld\n", sum);
      }
    } else if (cnt == 4) {
      if (sum >= 3099) {
        printf("%lld\n", sum);
      } else {
        printf("1%04lld\n", sum);
      }
    } else if (cnt == 5) {
      if (sum >= 13099) {
        printf("%lld\n", sum);
      } else {
        printf("1%05lld\n", sum);
      }
    } else if (cnt == 6) {
      if (sum >= 113099) {
        printf("%lld\n", sum);
      } else {
        printf("1%06lld\n", sum);
      }
    } else if (cnt == 7) {
      if (sum >= 1113099) {
        printf("%lld\n", sum);
      } else {
        printf("1%07lld\n", sum);
      }
    } else if (cnt == 8) {
      if (sum >= 11113099) {
        printf("%lld\n", sum);
      } else {
        printf("1%08lld\n", sum);
      }
    } else if (cnt == 9) {
      if (sum >= 111113099) {
        printf("%lld\n", sum);
      } else {
        printf("1%09lld\n", sum);
      }
    }
  }
  return 0;
}
