#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    int x = s.size() - 4;
    long long sum = 0;
    for (int i = 0; i < x; i++) {
      sum = sum * 10 + (s[i + 4] - '0');
    }
    long long p = 10, val = 0;
    for (int i = 1; i < x; i++) {
      val += p;
      p *= 10;
    }
    while (1989 + val > sum) sum += p;
    cout << sum << endl;
  }
  return 0;
}
