#include <bits/stdc++.h>
using namespace std;
int least_ending(int n, int ending, float multiple) {
  int l;
  if (ending >= n)
    l = 0;
  else
    l = ceil((n - ending) / multiple);
  return multiple * l + ending;
}
int main() {
  int n, shor;
  string s;
  cin >> n;
  getline(cin, s);
  while (n > 0) {
    getline(cin, s);
    shor = atoi(s.substr(4, s.length() - 4).c_str());
    int multiple = 10;
    int c = s.length() - 4;
    int res = 1988;
    while (c > 0) {
      res = least_ending(res + 1, shor % multiple, multiple);
      multiple *= 10;
      c--;
    }
    cout << res << endl;
    n--;
  }
  return 0;
}
