#include <bits/stdc++.h>
const int MOD = 1000000007;
const int N = 1e3 + 15;
const int maxn = 60000 + 1000;
const int letter = 130;
const int INF = 1e17;
const double pi = acos(-1.0);
const double eps = 1e-8;
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n;
int main() {
  n = read();
  while (n--) {
    char s[20];
    scanf("%s", s);
    int len = strlen(s), aim = 0, cnt = 0;
    for (int i = 0; i < len; i++) {
      if ('0' <= s[i] && s[i] <= '9') cnt++, aim = aim * 10 + s[i] - '0';
    }
    int ten = 10, f = 0;
    for (int i = 1; i < cnt; i++) {
      f += ten, ten *= 10;
    }
    while (aim < f + 1989) aim += ten;
    printf("%d\n", aim);
  }
  return 0;
}
