#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  char s[20];
  scanf("%d", &t);
  while (t--) {
    cin >> s;
    int k = strlen(s + 4), year = atoi(s + 4), F = 0, tenpow = 10;
    for (int i = 1; i < k; i++) {
      F += tenpow;
      tenpow *= 10;
    }
    while (year < 1989 + F) year += tenpow;
    printf("%d\n", year);
  }
  return 0;
}
