#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  char c;
  string s, x;
  while (n--) {
    cin >> c >> c >> c >> c;
    cin >> s;
    reverse(s.begin(), s.end());
    x = string(11, '0');
    x[0] = '9';
    x[1] = '8';
    x[2] = '9';
    x[3] = '1';
    for (int i = 0; i < s.size(); i++) {
      while (x[i] > '9') {
        x[i] -= 10;
        x[i + 1]++;
      }
      while (x[i] != s[i]) {
        x[i]++;
        if (x[i] > '9') {
          x[i] = '0';
          x[i + 1]++;
        }
      }
      if (i == s.size() - 1) break;
      x[i + 1]++;
    }
    for (int i = 0; i < 10; i++) {
      while (x[i] > '9') {
        x[i] -= 10;
        x[i + 1]++;
      }
    }
    reverse(x.begin(), x.end());
    for (int i = 0; i < 11; i++) {
      if (x[i] != '0') {
        cout << x.substr(i) << endl;
        break;
      }
    }
  }
}
