#include <bits/stdc++.h>
using namespace std;
unsigned power(unsigned val, unsigned _pow = 0) {
  if (_pow <= 0) return 1;
  return val * power(val, _pow - 1);
}
int str2int(const string &str) {
  stringstream ss(str);
  int num;
  if ((ss >> num).fail()) {
  }
  return num;
}
int n, m, temp;
bool comp(pair<int, pair<string, int> > x, pair<int, pair<string, int> > y) {
  return x.first < y.first;
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  int n;
  char inp[9 + 5];
  scanf("%d", &n);
  while (n--) {
    scanf("%s", &inp);
    int length = strlen(inp + 4), abbrev = atoi(inp + 4), digitsBef = 0,
        pow = 10;
    for (int i = 0; i < length - 1; ++i) {
      digitsBef += pow;
      pow *= 10;
    }
    for (; abbrev < 1989 + digitsBef;) abbrev += pow;
    printf("%d\n", abbrev);
  }
}
