#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {
    int x, tens = 10, start = 1989;
    string str;
    cin >> str;
    str = str.substr(4);
    x = atoi(str.c_str());
    for (int i = 1; i < str.size(); i++) {
      start += tens;
      tens *= 10;
    }
    while (x < start) {
      x += tens;
    }
    cout << x << endl;
  }
  return 0;
}
