#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e2 + 9;
const long long inf = 1e9 + 9;
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    string a;
    cin >> a;
    int len = a.size();
    a = a.substr(4, len - 4);
    len = a.size();
    long long x = 0;
    for (int i = 0; i < len; i++) {
      x = x * 10LL + (a[i] - '0') * 1LL;
    }
    long long ans = 0, pos = 10LL;
    for (int i = 0; i < len - 1; i++) {
      ans += pos;
      pos *= 10LL;
    }
    while (x < 1989 + ans) x += pos;
    printf("%lld\n", x);
  }
  return 0;
}
