#include <bits/stdc++.h>
using namespace std;
template <class C>
void mini(C& a4, C b4) {
  a4 = min(a4, b4);
}
template <class C>
void maxi(C& a4, C b4) {
  a4 = max(a4, b4);
}
template <class T1, class T2>
ostream& operator<<(ostream& rout, pair<T1, T2> pair) {
  return rout << "(" << pair.first << ", " << pair.second << ")";
}
int main() {
  int t;
  cin >> t;
  for (int _ = 0; _ < (t); ++_) {
    string s;
    cin >> s;
    s = s.substr(4);
    int l = ((int)(s).size());
    int beg = 1989;
    int pw = 10;
    for (int i = 0; i < (l - 1); ++i) {
      beg += pw;
      pw *= 10;
    }
    stringstream ss(s);
    int val;
    ss >> val;
    while (val < beg) val += pw;
    cout << val << endl;
  }
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  return 0;
}
