#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 100001;
int main() {
  int n;
  long p10, pivot, val, k;
  string s, t;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> s;
    s = s.substr(4);
    pivot = 1988;
    p10 = 1;
    val = 0;
    for (int j = s.size() - 1; j >= 0; --j) {
      val = (s[j] - '0') * p10 + val;
      p10 *= 10;
      if (val > pivot)
        k = 0;
      else
        k = (pivot - val) / p10 + 1;
      pivot = p10 * k + val;
    }
    cout << pivot << "\n";
  }
  return 0;
}
