#include <bits/stdc++.h>
using namespace std;
int n, awal, temp, a, tambah;
string input;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    a = 0;
    awal = 1988;
    tambah = 1;
    cin >> input;
    for (int i = 4; i < input.length(); i++) {
      a *= 10;
      a += (input[i] - '0');
    }
    for (int i = 0; i < input.length() - 4; i++) {
      temp = a % (tambah * 10);
      do {
        awal += tambah;
      } while (awal % (tambah * 10) != temp);
      tambah *= 10;
    }
    cout << awal << endl;
  }
}
