#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  int ans;
  for (int i = 0; i < n; i++) {
    int q = 0;
    cin >> s;
    s = s.substr(4);
    int len = s.length();
    for (int i = 0; i < len; i++) q = q * 10 + s[i] - '0';
    int tmp = 0;
    int ten = 10;
    for (int i = 1; i < len; i++) {
      tmp += ten;
      ten *= 10;
    }
    while (tmp + 1989 > q) q += ten;
    cout << q << endl;
  }
  return 0;
}
