#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, j, z, x = 10, k = 0, year = 0, l = 0, f = 0;
  string s;
  cin >> n;
  while (n--) {
    cin >> s;
    x = 10;
    f = 0;
    year = 0;
    k = s.length() - 4;
    for (i = 1; i < k; i++) {
      f += x;
      x *= 10;
    }
    for (i = 4; i < s.length(); i++) {
      year = year * 10 + 10 * (s[i] - 48);
    }
    year /= 10;
    while (year < 1989 + f) {
      year += x;
    }
    cout << year << endl;
  }
  return 0;
}
