#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
long long a[maxn];
int test;
char ch;
string s, b[maxn];
int num(string str) {
  int s = 0;
  for (int i = 0; i < str.length(); ++i) {
    s = s * 10 + (str[i] - '0');
  }
  return s;
}
string strg(long long x) {
  string s = "";
  while (x) {
    s = char(x % 10 + '0') + s;
    x /= 10;
  }
  return s;
}
int main() {
  a[1] = 1989;
  b[1] = strg(a[1]);
  long long tmp = 10;
  for (int i = 2; i <= 10; ++i) {
    a[i] = a[i - 1] + tmp;
    b[i] = strg(a[i]);
    tmp *= 10;
  }
  cin >> test;
  for (int t = 1; t <= test; ++t) {
    for (int i = 1; i <= 4; ++i) cin >> ch;
    cin >> s;
    if (b[s.length()].length() == s.length()) {
      if (num(s) >= a[s.length()])
        cout << s << "\n";
      else
        cout << "1" << s << "\n";
    } else {
      if (b[s.length()].substr(b[s.length()].length() - s.length(),
                               s.length()) <= s) {
        cout << b[s.length()].substr(0, b[s.length()].length() - s.length())
             << s << "\n";
      } else
        cout << num(b[s.length()].substr(0,
                                         b[s.length()].length() - s.length())) +
                    1
             << s << "\n";
    }
  }
  return 0;
}
