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