#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9 + 7;
const int N = 1e6 + 10;
int n, m, k, t;
bool vis[N];
int main() {
  memset(vis, 0, sizeof(vis));
  scanf("%d", &n);
  while (n--) {
    string s;
    cin >> s;
    k = s.size() - 4;
    int tmp = 0;
    for (int i = 4; i < s.size(); i++) {
      tmp = tmp * 10 + s[i] - '0';
    }
    int cnt = 0;
    t = 10;
    for (int i = 1; i < k; i++) {
      cnt += t;
      t *= 10;
    }
    while (1989 + cnt > tmp) tmp += t;
    printf("%d\n", tmp);
  }
  return 0;
}
