#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int N = 0;
string s;
long long solve(string s) {
  int n = s.length();
  long long ans = 1988;
  for (auto i = (n - 1); i >= (4); i--) {
    long long mul = 1, add = 0;
    for (auto j = (i); j < (n); j++) {
      mul = 10 * mul;
      add = 10 * add + s[j] - '0';
    }
    long long nx = max(mul + ans - add, 0LL) / mul;
    ans = nx * mul + add;
  }
  return ans;
}
int main() {
  int test;
  cin >> test;
  while (test--) {
    cin >> s;
    cout << solve(s) << '\n';
  }
}
