#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    char s[105];
    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;
    cout << year << '\n';
  }
}
