International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition.

For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995.

You are given a list of abbreviations. For each of them determine the year it stands for.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process. 

Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits.

Output

For each abbreviation given in the input, find the year of the corresponding Olympiad.

Examples

Input

5
IAO'15
IAO'2015
IAO'1
IAO'9
IAO'0


Output

2015
12015
1991
1989
1990


Input

4
IAO'9
IAO'99
IAO'999
IAO'9999


Output

1989
1999
2999
9999
#include <bits/stdc++.h>
using namespace std;
int n;
string a, b;
int beta(string b) {
  int b_l = b.length(), s = 0;
  for (int i = 0; i < b_l; i++) s = s * 10 + (int)(b[i] - '0');
  return s;
}
int alpha(string a) {
  if (a.length() == 1) {
    if (a[0] == '9') return 1989;
    return 1990 + (int)(a[0] - '0');
  }
  if (a.length() == 2) {
    if (a == "99") return 1999;
    return 2000 + beta(a);
  }
  if (a.length() == 3) {
    if (a == "099") return 2099;
    if (a[0] == '0') return 3000 + beta(a);
    return 2000 + beta(a);
  }
  if (a.length() == 4) {
    if (a < "3099") return 10000 + beta(a);
    return beta(a);
  }
  if (a.length() == 5) {
    if (a < "13099") return 100000 + beta(a);
    return beta(a);
  }
  if (a.length() == 6) {
    if (a < "113099") return 1000000 + beta(a);
    return beta(a);
  }
  if (a.length() == 7) {
    if (a < "1113099") return 10000000 + beta(a);
    return beta(a);
  }
  if (a.length() == 8) {
    if (a < "11113099") return 100000000 + beta(a);
    return beta(a);
  }
  if (a.length() == 9) {
    if (a < "111113099") return 1000000000 + beta(a);
    return beta(a);
  }
  if (a.length() == 10) {
    if (a < "1111113099") return 10000000000 + beta(a);
    return beta(a);
  }
}
int main() {
  int n;
  string s = "";
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    s = s.substr(4, s.length() - 4);
    cout << alpha(s) << "\n";
  }
}
