#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
int n, val;
string s;
int main() {
  {
    cin >> n;
    while (n--) {
      cin >> s;
      s = s.substr(4);
      val = atoi(s.c_str());
      ;
      int len = s.length();
      long long int start = 1989;
      int cur = 1;
      long long int mul = 10;
      while (cur < len) {
        start += mul;
        mul *= 10;
        cur++;
      };
      val = (start / mul) * mul + val;
      ;
      while (val < start) {
        val += mul;
      }
      cout << val << '\n';
    }
  };
  return 0;
}
