#include <bits/stdc++.h>
using namespace std;
int findlength(int num) {
  int ans = 1;
  while (num) {
    num /= 10;
    ans *= 10;
  }
  return ans;
}
int solve(int num, int suf, int siz) {
  if (num < suf) {
    return suf;
  }
  int ans = max(0, (num - suf) / siz + 1);
  return siz * ans + suf;
}
int main() {
  int n;
  cin >> n;
  while (n--) {
    string s, t;
    cin >> s;
    int num = 0, p = 1, ans = 1988, siz = 1;
    for (int i = 4; i < s.size(); i++) {
      t += s[i];
    }
    for (int i = t.size() - 1; i >= 0; i--) {
      num += (t[i] - '0') * p;
      p *= 10;
      siz *= 10;
      ans = solve(ans, num, siz);
    }
    cout << ans << endl;
  }
  return 0;
}
