#include <bits/stdc++.h>
using namespace std;
int n;
char *s, ch[110];
int main() {
  scanf("%d", &n);
  for (int k = 1; k <= n; ++k) {
    scanf("%s", ch);
    s = ch;
    for (int i = 0; i < 4; ++i) s++;
    int len = strlen(s);
    int now = 1988;
    int d = 1, x = 0;
    for (int i = len - 1; i >= 0; --i) {
      x += d * (s[i] - '0');
      d *= 10;
      int sx = 0;
      sx = (now + 1 - x + d - 1) / d;
      now = sx * d + x;
    }
    printf("%d\n", now);
  }
}
