#include <bits/stdc++.h>
using namespace std;
int T;
char s[20];
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%s", s + 1);
    int n = strlen(s + 1), num = 0;
    for (int i = 5; i <= n; i++) num = num * 10 + s[i] - '0';
    if (n == 5) {
      if (num == 9)
        puts("1989");
      else
        printf("199%s\n", s + 5);
    }
    if (n == 6) {
      if (num == 99)
        puts("1999");
      else
        printf("20%s\n", s + 5);
    }
    if (n == 7) {
      if (num == 99)
        puts("2099");
      else if (num >= 100)
        printf("2%s\n", s + 5);
      else
        printf("3%s\n", s + 5);
    }
    if (n == 8) {
      if (num >= 3099)
        printf("%d\n", num);
      else
        printf("1%s\n", s + 5);
    }
    if (n > 8) {
      if (s[5] == '0')
        printf("1%s\n", s + 5);
      else {
        int now = 0;
        for (int i = 5; i <= n - 4; i++) now = now * 10 + 1;
        now = now * 10000 + 3098;
        if (num > now)
          printf("%d\n", num);
        else
          printf("1%s\n", s + 5);
      }
    }
  }
}
