#include <bits/stdc++.h>
using namespace std;
const int N = 200000;
using namespace std;
int i, j, a[N], n, fl;
char str[N];
string s;
long long tec, st;
int main() {
  scanf("%d\n", &n);
  for (i = 0; i < n; i++) {
    gets(str);
    s = string(str);
    s.erase(0, 4);
    tec = 1988;
    st = 1;
    for (j = s.length() - 1; j >= 0; j--) {
      fl = 0;
      while ((tec / st) % 10 != s[j] - '0') tec += st, fl = 1;
      st *= 10;
      if (fl == 0) tec += st;
    }
    printf("%I64d\n", tec);
  }
  return 0;
}
