#include <bits/stdc++.h>
using namespace std;
int n;
char str[25];
int a[15] = {0, 0, 0, 0, 3099, 13099, 113099, 1113099, 11113099, 111113099};
int main() {
  long long num;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", str);
    num = 0;
    int tmp = 1;
    int len = strlen(str);
    for (int j = 0; j < 15; j++) {
      if (!isdigit(str[len - j - 1])) {
        break;
      }
      num += (str[len - j - 1] - '0') * tmp;
      tmp *= 10;
    }
    if (len > 7) {
      if (num < a[len - 4]) {
        str[len + 1] = str[len];
        for (int j = len - 1; isdigit(str[j]); j--) {
          str[j + 1] = str[j];
        }
        str[4] = '1';
      }
      printf("%s\n", str + 4);
    } else if (len == 5) {
      if (num == 9) {
        num = 1989;
      } else {
        num += 1990;
      }
      printf("%d\n", (int)num);
    } else if (len == 6) {
      if (num == 99) {
        num = 1999;
      } else {
        num += 2000;
      }
      printf("%d\n", (int)num);
    } else if (len == 7) {
      if (num < 99) {
        num += 3000;
      } else {
        num += 2000;
      }
      printf("%d\n", (int)num);
    }
  }
  return 0;
}
