#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin.clear();
  fflush(stdin);
  int n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    int year = stoi(s.substr(4, s.size() - 4)), p = 1, x = 1989;
    for (int i = 0; i < s.size() - 5; i++) {
      p *= 10;
      x += p;
    }
    p *= 10;
    while (year < x) {
      year += p;
    }
    cout << year << endl;
  }
  return 0;
}
