#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7, maxn = 100005, ln = 17;
const int shift = 30, etf = mod - 1;
const long long int inf = (long long int)1e18 + 1;
const double PI = (double)3.141592653589793238, EPSILON = 1e-10;
long long int syear[1005], cnt[1005];
void pre() {
  long long int x = 1989, mul = 1;
  for (int i = 1; i < 15; i++) {
    syear[i] = x;
    mul *= 10;
    cnt[i] = mul;
    x += mul;
  }
}
int main() {
  pre();
  int n;
  cin >> n;
  while (n--) {
    long long int ans;
    string s;
    cin >> s;
    int len = s.length() - 4;
    long long int num = 0;
    for (int i = 4; i < s.length(); i++) {
      num = num * 10 + s[i] - '0';
    }
    long long int st = syear[len] % cnt[len];
    if (num >= st) {
      ans = syear[len] - st + num;
    } else {
      ans = syear[len] - st + cnt[len] + num;
    }
    cout << ans << endl;
  }
  return 0;
}

### Prompt

In cpp, your task is to solve the following problem:

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7, maxn = 100005, ln = 17;
const int shift = 30, etf = mod - 1;
const long long int inf = (long long int)1e18 + 1;
const double PI = (double)3.141592653589793238, EPSILON = 1e-10;
long long int syear[1005], cnt[1005];
void pre() {
  long long int x = 1989, mul = 1;
  for (int i = 1; i < 15; i++) {
    syear[i] = x;
    mul *= 10;
    cnt[i] = mul;
    x += mul;
  }
}
int main() {
  pre();
  int n;
  cin >> n;
  while (n--) {
    long long int ans;
    string s;
    cin >> s;
    int len = s.length() - 4;
    long long int num = 0;
    for (int i = 4; i < s.length(); i++) {
      num = num * 10 + s[i] - '0';
    }
    long long int st = syear[len] % cnt[len];
    if (num >= st) {
      ans = syear[len] - st + num;
    } else {
      ans = syear[len] - st + cnt[len] + num;
    }
    cout << ans << endl;
  }
  return 0;
}

```