#include <bits/stdc++.h>
using namespace std;
int n;
char s[55];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> n;
  while (n--) {
    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';
  }
  return 0;
}
