#include <bits/stdc++.h>
using namespace std;
int f(long long n, int d) {
  while (d) {
    n = n / 10;
    d--;
  }
  return n % 10;
}
int main() {
  long long n, i, digit, x, y, z;
  long long weight;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    long long num = 1988;
    for (i = s.length() - 1, weight = 1, digit = 0; i >= 4;
         i--, weight *= 10, digit++) {
      x = s[i] - '0';
      x = x - f(num, digit);
      if (x < 1) x += 10;
      x *= weight;
      num += x;
    }
    cout << num << endl;
  }
  return 0;
}
