#include <bits/stdc++.h>
int main() {
  int n, i, r;
  std::string s;
  scanf("%d/n", &n);
  for (i = 0; i < n; i++) {
    std::cin >> s;
    long long y = 0, ans;
    int x = s.size() - 4;
    for (int j = 0; j < x; j++) {
      y *= 10;
      y += s[j + 4] - '0';
    }
    if (x == 1) {
      ans = 1990 + y;
      if (ans == 1999) ans -= 10;
    } else if (x == 2) {
      ans = 2000 + y;
      if (ans == 2099) ans -= 100;
    } else if (x == 3) {
      ans = 2000 + y;
      if (ans < 2099) ans += 1000;
    } else if (x == 4) {
      ans = y;
      if (ans < 3099) ans += 10000;
    } else if (x == 5) {
      ans = y;
      if (ans < 13099) ans += 100000;
    } else if (x == 6) {
      ans = y;
      if (ans < 113099) ans += 1000000;
    } else if (x == 7) {
      ans = y;
      if (ans < 1113099) ans += 10000000;
    } else if (x == 8) {
      ans = y;
      if (ans < 11113099) ans += 100000000;
    } else if (x == 9) {
      ans = y;
      if (ans < 111113099) ans += 1000000000;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
