#include <bits/stdc++.h>
using namespace std;
char s[100];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%s", s);
    int l = strlen(s);
    int ans = 1988, t = 1, w = 0;
    for (int i = l - 1; i > 3; i--) {
      w = w + t * (s[i] - 48);
      t = t * 10;
      if (ans % t < w)
        ans = ans / t * t + w;
      else
        ans = (ans / t + 1) * t + w;
    }
    printf("%d\n", ans);
  }
  return 0;
}
