#include <bits/stdc++.h>
using namespace std;
const int iinf = 0x7fffffff;
const long long linf = ~(1LL << 63);
template <typename T>
inline T gcd(T a, T b) {
  if (a < b) return gcd(b, a);
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <typename C>
inline void sort(C& v) {
  sort(v.begin(), v.end());
}
inline void println(int u) { printf("%d\n", u); }
inline void printsp(int u) { printf("%d ", u); }
const int maxn = 1010;
int main() {
  ios::sync_with_stdio(0);
  int T;
  cin >> T;
  while (T--) {
    string target;
    cin >> target;
    for (int i = 0; i < target.size(); i++) {
      if (target[i] == '\'') {
        target = target.substr(i + 1);
        break;
      }
    }
    long long ten = 1;
    long long key = 1989;
    long long prefix = 198;
    long long ans = 0;
    while (target.size() > 0) {
      ans += ten * (target[target.size() - 1] - '0');
      target = target.substr(0, target.size() - 1);
      while ((prefix * ten * 10 + ans <= key && ten > 1) ||
             (prefix * ten * 10 + ans < key)) {
        prefix += 1;
      }
      key = prefix * ten * 10 + ans;
      prefix /= 10;
      ten *= 10;
    }
    cout << key << endl;
  }
  return 0;
}
