#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  ios::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    cin.tie(0);
    cin >> a;
    int n = a.size() - 4;
    long long x = 1989;
    long long y = 1, s = 0;
    for (int i = 1; i <= n; i++) {
      y *= 10;
    }
    for (int i = 4; i < a.size(); i++) {
      s *= 10;
      s += a[i] - '0';
    }
    long long l = x, p = 10;
    for (int i = 1; i < n; i++) {
      l += p;
      p *= 10;
    }
    while (s < x || s < l) {
      s += y;
    }
    cout << s << "\n";
  }
}
