#include <bits/stdc++.h>
using namespace std;
const int N = (int)3 * 10e3 + 1;
string s;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    int k = s.length() - 4;
    int number = stoi(s.substr(4));
    int x = 0;
    int p = 10;
    for (int i = 1; i < k; i++) {
      x += p;
      p *= 10;
    }
    while (number < 1989 + x) number += p;
    cout << number << endl;
  }
  return 0;
}
