#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    int L = s.length() - 4;
    s = s.substr(4, L);
    set<long long> used;
    for (int i = L - 1; i >= 0; i--) {
      string s2 = s.substr(i, L - i);
      long long x = 0;
      if (s2[0] == '0') x++;
      while (true) {
        long long y = x;
        for (int j = 0; j < L - i; j++) y = y * 10 + s2[j] - '0';
        if (y < 1989 || used.find(y) != used.end()) {
          x++;
          continue;
        }
        used.insert(y);
        if (i == 0) cout << y << "\n";
        break;
      }
    }
  }
  return 0;
}
