#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<pair<int, int> > A;
  A.push_back(make_pair(1989, 1));
  for (int i = 1; i <= 9; ++i) {
    pair<int, int> x = A.back();
    x.second *= 10;
    x.first += x.second;
    A.push_back(x);
  }
  int t;
  cin >> t;
  while (t--) {
    string inp;
    cin >> inp;
    inp = inp.substr(4);
    int len = inp.length(), num = 0;
    for (int i = 0; i < len; ++i) num = num * 10 + (inp[i] - '0');
    int lnum = A[len - 1].first % A[len].second;
    if (num >= lnum) {
      int ans = (A[len - 1].first / A[len].second) * A[len].second;
      ans += num;
      cout << ans << "\n";
    } else {
      int ans = (A[len].first / A[len].second) * A[len].second;
      ans += num;
      cout << ans << "\n";
    }
  }
  return 0;
}
