#include <bits/stdc++.h>
using namespace std;
const int mmmm = 1111;
int n;
char s[mmmm];
int a[mmmm], f[mmmm];
void qwe() {
  a[0] = 1989;
  f[0] = 1;
  for (int i = 1; i <= 9; i++) {
    f[i] = f[i - 1] * 10;
    a[i] = a[i - 1] + f[i];
  }
}
int main() {
  qwe();
  while (scanf("%d", &n) != EOF) {
    for (int i = 1; i <= n; i++) {
      scanf("%s", s);
      int l = strlen(s) - 4;
      int c = 0;
      for (int i = 4; i < l + 4; i++) {
        c = c * 10 + s[i] - '0';
      }
      int asd = a[l - 1];
      int zxc = a[l];
      int t1 = asd / f[l] * f[l] + c;
      int t2 = zxc / f[l] * f[l] + c;
      if (t1 >= asd && t1 < zxc) {
        printf("%d\n", t1);
      } else {
        printf("%d\n", t2);
      }
    }
  }
  return 0;
}
