#include <bits/stdc++.h>
using namespace std;
int t;
string s;
int main() {
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int ten = 10, k = s.size() - 4;
    long long sum = 0;
    long long year = 0;
    long long t = 1;
    for (int i = s.size() - 1; i > 3; i--) {
      year += t * (int(s[i]) - 48);
      t *= 10;
    }
    for (int i = 1; i < k; i++) {
      sum += ten;
      ten *= 10;
    }
    while (year < 1989 + sum) {
      year += ten;
    }
    cout << year << endl;
  }
  return 0;
}
