#include <bits/stdc++.h>
using namespace std;
int t, yr, len, tpw, ff;
char s[50];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> t;
  while (t--) {
    cin >> s;
    len = strlen(s + 4);
    yr = atoi(s + 4);
    ff = 0;
    tpw = 10;
    for (int i = 0; i < len - 1; i++) {
      ff += tpw;
      tpw = tpw * 10;
    }
    while (yr < 1989 + ff) yr += tpw;
    cout << yr << endl;
  }
}
