#include <bits/stdc++.h>
using namespace std;
const int N = (int)5e5 + 4;
const int inf = (int)1e9 + 7;
const long double eps = 1e-7;
const int K = 12;
const int M = 1001;
int main() {
  int n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    string t = s.substr(0, (int)s.size() - 4);
    int x = 0;
    int f = 0;
    int d = 1;
    for (char c : t) {
      x += (c - '0') * d;
      d *= 10;
      f += d;
    }
    f -= d;
    for (; x < 1989 + f; x += d)
      ;
    cout << x << endl;
  }
  return 0;
}
