#include <bits/stdc++.h>
using namespace std;
int N;
vector<string> vs;
int main() {
  scanf("%d", &N);
  vs.assign(N, string(""));
  for (int i = 0; i < N; i++) {
    char s[15];
    scanf("%s", s);
    vs[i] = s;
    vs[i] = vs[i].substr(4);
  }
  for (int i = 0; i < N; i++) {
    long long year = 1988, x = stoll(vs[i]), pow_10 = 1;
    for (int j = 0; j < vs[i].size(); j++) {
      year += pow_10;
      pow_10 *= 10;
    }
    long long y = year % pow_10;
    if (x < y) {
      x += pow_10;
    }
    vs[i] = to_string(year + (x - y));
  }
  for (int i = 0; i < N; i++) {
    printf("%s\n", vs[i].c_str());
  }
  return 0;
}
