#include <bits/stdc++.h>
using namespace std;
char s[100];
int main() {
  int n;
  cin >> n;
  while (n--) {
    scanf(" %s", s);
    int k = strlen(s) - 4;
    int y = atoi(s + 4), f = 0, pw = 10;
    for (int i = 0; i < k - 1; i++) f += pw, pw *= 10;
    while (y < 1989 + f) y += pw;
    cout << y << '\n';
  }
}
