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