#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
int n;
stringstream ss;
const int N = 1000 + 5;
char s[N];
char c[N];
int T;
int m;
string F(string s);
string G(string s);
int k = 1989;
string G(string s) {
  if (((int)((s).size())) == 1) {
    if (s[0] == '9')
      return to_string(k);
    else
      return to_string(k + 1 + s[0] - '0');
  }
  if (((int)((s).size())) == 2) {
    if (s[0] == '9' && s[1] == '9')
      return to_string(1999);
    else
      return to_string(2000 + stoi(s));
  }
  if (((int)((s).size())) == 3) {
    if (s[0] == '0') {
      if (s[1] == '9' && s[2] == '9')
        return to_string(2099);
      else
        return to_string(3000 + stoi(s));
    } else
      return to_string(2000 + stoi(s));
  }
  string u;
  for (int i = 0; i < (int)(((int)((s).size()))); ++i) u += '1';
  u[((int)((s).size())) - 1] = '9';
  u[((int)((s).size())) - 2] = '9';
  u[((int)((s).size())) - 3] = '0';
  u[((int)((s).size())) - 4] = '3';
  if (s < u) return '1' + s;
  return s;
}
void solve() {
  scanf("%d", &T);
  while (T--) {
    scanf("%s", c);
    int m = strlen(c);
    for (int i = 4; i <= m; ++i) s[i - 4] = c[i];
    m -= 4;
    if (m <= 1) {
      if (s[0] == '9') {
        printf("%d\n", k);
      } else {
        printf("%d\n", k + 1 + s[0] - '0');
      }
      continue;
    }
    string u;
    for (int i = 0; i < (int)(m); ++i) u += s[i];
    printf("%s\n", G(u).c_str());
  }
}
void testgen() {
  FILE* f = fopen("input.txt", "w");
  fclose(f);
}
int main() {
  cout << fixed;
  cout.precision(13);
  cerr << fixed;
  cerr.precision(3);
  solve();
  return 0;
}
