#include <bits/stdc++.h>
using namespace std;
const long long N = 1000006, MOD = 1e9 + 7, INF = 1e16;
long long a[N], b[N], ans, n, m, mx, mn, l, r, x, y, z, o, k, q = 1;
vector<int> v[N];
char c;
string s;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  cin >> q;
  while (q--) {
    cin >> s;
    n = s.size() - 4;
    y = 1;
    x = 0;
    for (int i = 4; i < s.size(); i++) y *= 10, x *= 10, x += (s[i] - '0');
    o = (y * 10) / 9 - 1;
    cout << ((o + 1989 - x - 1) / y) * y + x << endl;
  }
}
