#include <bits/stdc++.h>
using namespace std;
int t, ss, res;
string s;
void cal() {
  if (ss == 1)
    cout << (res == 9 ? 1989 : 1990 + res) << '\n';
  else if (ss == 2)
    cout << (res == 99 ? 1999 : 2000 + res) << '\n';
  else if (ss == 3)
    cout << (res >= 0 && res < 99 ? 3000 + res : 2000 + res) << '\n';
  else if ((ss == 4 && res < 3099) || (ss == 5 && res < 13099) ||
           (ss == 6 && res < 113099) || (ss == 7 && res < 1113099) ||
           (ss == 8 && res < 11113099) || (ss == 9 && res < 111113099)) {
    cout << 1;
    for (int i = 4; i < ss + 4; i++) cout << s[i];
    cout << '\n';
  } else
    cout << res << '\n';
}
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cin >> t;
  while (t--) {
    res = 0;
    cin >> s;
    ss = s.size();
    for (int i = 4; i < ss; i++) res *= 10, res += s[i] - '0';
    ss -= 4;
    cal();
  }
  return 0;
}
