#include <bits/stdc++.h>
using namespace std;
const unsigned long long z = 1989;
int main() {
  set<unsigned long long> mn;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    mn.clear();
    string s, ss;
    unsigned long long num = 0, d = 1;
    cin >> s;
    for (int j = 0; j < s.length(); j++)
      if ('0' <= s[j] && s[j] <= '9') {
        num = num * 10 + s[j] - '0';
        ss += s[j];
      }
    unsigned long long ans;
    for (int l = 1; l <= ss.length(); l++) {
      d *= 10;
      unsigned long long x = num % d;
      for (unsigned long long j = 0; j <= pow(10, 9 - l); j++) {
        ans = j * d + x;
        if ((ans >= z) && (mn.find(ans) == mn.end())) {
          mn.insert(ans);
          break;
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
