#include <bits/stdc++.h>
using namespace std;
long long mod = 1000003;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    string t = s.substr(4, 10);
    long long cur = 1988;
    long long deg10 = 1;
    long long res = 0;
    for (int k = t.size() - 1; k >= 0; k--) {
      res += (long long)(t[k] - '0') * deg10;
      deg10 *= 10;
      long long add = (res + deg10 - (cur) % deg10) % deg10;
      if (add == 0) add = deg10;
      cur += add;
    }
    cout << cur << endl;
  }
}
