#include <bits/stdc++.h>
using namespace std;
template <typename T>
using Grid = vector<vector<T>>;
const double PI = acos(-1);
long long pow(int k) {
  long long ret = 1;
  while (k--) ret *= 10;
  return ret;
}
long long pre(int k) {
  long long ret = 0;
  while (k--) ret += pow(k);
  ret -= 1;
  return ret;
}
long long num(string s) {
  int i = 0;
  while (s[i] != '\'') i++;
  i++;
  long long ret = 0;
  while (i != s.length()) ret *= 10, ret += s[i] - '0', i++;
  return ret;
}
int len(string s) {
  int i = 0;
  while (s[i] != '\'') i++;
  return s.length() - i - 1;
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<string> xs(n);
  vector<long long> x(n);
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    xs[i] = s;
    x[i] = num(s);
  }
  long long base = 1989;
  for (int i = 0; i < x.size(); i++) {
    int abbr_len = len(xs[i]);
    long long from = base + pre(abbr_len);
    long long to = base + pre(abbr_len) + pow(abbr_len);
    long long step = pow(abbr_len);
    long long ans = x[i];
    while (ans < from) ans += step;
    cout << ans << endl;
  }
}
