#include <bits/stdc++.h>
using namespace std;
char s[100];
int num[100];
long long pre[100];
long long find(long long n, int len) {
  long long t = n;
  int m = 0;
  while (t) {
    num[m++] = t % 10;
    t /= 10;
  }
  while (m < len) {
    num[m++] = 0;
  }
  t = 0;
  long long b = 1;
  for (int i = 0; i < (m); ++i) {
    t = t + b * num[i];
    b *= 10;
    for (int j = 0; j < 2000; ++j) {
      long long s = b * j + t;
      if (s >= 1989) {
        bool ok = 1;
        for (int k = 0; k < (i); ++k) {
          if (s == pre[k]) {
            ok = 0;
            break;
          }
        }
        if (ok) {
          pre[i] = s;
          if (i == m - 1) return s;
          break;
        }
      }
    }
  }
  return 0;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n = 0;
    scanf(" %s", s);
    for (int i = 4; s[i]; ++i) n = n * 10 + s[i] - '0';
    printf("%I64d\n", find(n, strlen(s) - 4));
  }
  return 0;
}
