#include <bits/stdc++.h>
using namespace std;
vector<long long> start_years;
vector<long long> start_numbers;
vector<long long> mods;
void init() {
  long long start = 1989;
  start_years.resize(10);
  start_numbers.resize(10);
  mods.resize(10);
  start_years[0] = start;
  start_numbers[0] = 9;
  mods[0] = 10;
  long long p = 10;
  for (int i = 1; i < 10; ++i) {
    start_years[i] = start_years[i - 1] + p;
    p *= 10;
    start_numbers[i] = start_years[i] % p;
    mods[i] = p;
  }
}
long long solve(int i, long long num) {
  long long pos = num - start_numbers[i] + mods[i];
  pos %= mods[i];
  return start_years[i] + pos;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  init();
  int n = 0;
  cin >> n;
  for (int i = 0; i < (n); ++i) {
    string str;
    cin >> str;
    int len = str.size() - 4;
    stringstream ss(str.substr(4, len));
    long long num;
    ss >> num;
    cout << solve(len - 1, num) << endl;
  }
  return 0;
}
