#include <bits/stdc++.h>
using namespace std;
int cond = (long long)1;
char buf[10000];
map<string, long long> dp;
void solve() {
  scanf(" %s", buf);
  int n = strlen(buf);
  string s = string(buf + 4);
  long long pref = 1;
  long long last = 1988;
  for (auto i = (n - 1); i >= (4); --i) {
    pref *= 10;
    int cur;
    sscanf(buf + i, "%d", &cur);
    string sub = string(buf + i);
    long long x = cur;
    if (sub[0] == '0') x += pref;
    for (; x <= last; x += pref) {
    }
    last = x;
  }
  cout << last << endl;
}
const int multi = 1;
int main(int argc, char** argv) {
  ios::sync_with_stdio(false);
  cond = argc >= 2 && argv[1][0] == 'q' ? 1 << 30 : 0;
  int t;
  if (multi)
    scanf("%d", &t);
  else
    t = 1;
  for (auto i = (1); i <= (t); ++i) {
    if (cond) cerr << 59 << " " << i << endl;
    solve();
    fflush(stdout);
    cerr.flush();
  }
  return 0;
}
