#include <bits/stdc++.h>
using namespace ::std;
const int N = 1005;
int n;
string a;
long long get_next(long long v1, long long v2, long long p) {
  while (v2 <= v1) v2 += p;
  return v2;
}
int main() {
  scanf("%d", &n);
  while (n--) {
    cin >> a;
    long long now = 0, p = 1, ans = 1988;
    for (int i = (int)a.size() - 1; i >= 0; i--) {
      if (a[i] - '0' < 0 || a[i] - '0' >= 10) break;
      now += p * (a[i] - '0');
      p *= 10;
      ans = get_next(ans, now, p);
    }
    printf("%lld\n", ans);
  }
  return 0;
}
