#include <bits/stdc++.h>
using namespace std;
long long s[12], u, po;
char str[15];
int t, len, dig;
int main() {
  s[1] = 1989;
  po = 1;
  for (int i = (2); i <= (11); i++) {
    po *= 10;
    s[i] = s[i - 1] + po;
  }
  scanf("%d", &t);
  while (t--) {
    scanf("\n%s", str);
    len = strlen(str);
    dig = len - 4;
    u = 0;
    for (int i = (4); i <= (len - 1); i++) u = u * 10 + str[i] - '0';
    po = 1;
    for (int i = (1); i <= (dig); i++) po *= 10;
    if (u <= (s[dig + 1] - 1) % po)
      printf("%lld\n", (s[dig + 1] - 1) / po * po + u);
    else
      printf("%lld\n", s[dig] / po * po + u);
  }
  return 0;
}
