#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int main() {
  for (int i = 1989; i < 100000; i++) {
    int num = i;
    string s = "";
    while (num != 0) {
      string s1 = "";
      char c = num % 10 + '0';
      s1 += c;
      s1 += s;
      num /= 10;
      if (mp[s1] == 0) {
        mp[s1] = i;
        break;
      }
      s = s1;
    }
  }
  char s[100];
  int n;
  scanf("%d", &n);
  while (n--) {
    scanf("%s", s);
    string s1 = "";
    for (int i = 4; s[i] != '\0'; i++) s1 += s[i];
    if (s1.size() <= 3 || mp[s1] != 0)
      printf("%d\n", mp[s1]);
    else {
      string s2 = "";
      long long P = 1, number = 0;
      for (int i = s1.size() - 1; i >= s1.size() - 3; i--) {
        number = (s1[i] - '0') * P + number;
        P *= 10;
        s2 += s1[i];
      }
      reverse(s2.begin(), s2.end());
      long long num = mp[s2];
      for (int i = s1.size() - 4; i >= 0; i--) {
        if (P * (s1[i] - '0') + number > num)
          num = P * (s1[i] - '0') + number, number = P * (s1[i] - '0') + number;
        else
          num = P * (s1[i] - '0') + number + P * 10,
          number = P * (s1[i] - '0') + number;
        P *= 10;
      }
      printf("%lld\n", num);
    }
  }
}
