#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
const double eps = 1e-5;
const double pi = acos(-1);
int vis[20];
int a[15] = {1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1989};
int main() {
  int T;
  scanf("%d", &T);
  char s[10];
  while (T--) {
    scanf("%s", s);
    int len = strlen(s);
    int bas = s[len - 1] - '0';
    int extra = 0;
    int index = 1;
    int total = 0;
    int cur;
    for (int i = len - 1; s[i] >= '0' && s[i] <= '9'; i--) {
      extra += (s[i] - '0') * index;
      index *= 10;
      int pre = a[bas] / index - 1;
      bool flag = true;
      while (flag) {
        pre++;
        cur = pre * index + extra;
        if (cur < a[bas]) {
          continue;
        }
        flag = false;
        for (int j = 0; j < total; j++) {
          if (vis[j] == cur) {
            flag = true;
            break;
          }
        }
      }
      vis[total++] = cur;
    }
    printf("%d\n", vis[--total]);
  }
  return 0;
}
