#include <bits/stdc++.h>
using namespace std;
int T;
string s;
int main() {
  ios::sync_with_stdio(0);
  cin >> T;
  while (T--) {
    cin >> s;
    int n = s.size() - 4;
    s = s.substr(4, n);
    int a = 0;
    for (int i = 0; i < n; ++i) a = a * 10 + (int)s[i] - '0';
    int m = 0, year[11] = {0}, x = 0;
    for (int i = 1; i <= n; ++i) {
      if (i == 1)
        x = a % 10;
      else
        x = a % 10 * (int)(pow(10, i - 1) + 0.5) + x;
      a /= 10;
      int d = (int)(pow(10, i) + 0.5);
      for (int j = 0;; j += d)
        if (j + x >= 1989 && j + x > year[m]) {
          year[++m] = j + x;
          break;
        }
    }
    cout << year[m] << endl;
  }
}
