#include <bits/stdc++.h>
using namespace std;
int poww(int n) {
  int a = 1;
  for (int i = 1; i <= n; ++i) {
    a *= 10;
  }
  return a;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    int arr[9];
    int ind = 0;
    memset(arr, -1, sizeof(arr));
    for (int i = 4; i < s.length(); ++i) {
      char c = s[i];
      int a = (int)(c - '0');
      arr[ind++] = a;
    }
    int from = 1989 + 10 * (poww(ind - 1) - 1) / 9;
    int to = from + poww(ind);
    int end = 0;
    for (int i = ind - 1; i >= 0; --i) {
      end += arr[i] * poww(ind - 1 - i);
    }
    for (int k = 0; k <= 9; ++k) {
      bool p = false;
      int kk = k * poww(ind + 2);
      for (int i = 0; i <= 9; ++i) {
        int ii = i * poww(ind + 1);
        for (int j = 0; j <= 9; ++j) {
          int add = kk + ii + j * poww(ind);
          if (end + add >= from && end + add <= to) {
            end += add;
            p = true;
            break;
          }
        }
        if (p) break;
      }
      if (p) {
        cout << end << endl;
        break;
      }
    }
  }
  return 0;
}
