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
import java.io.*;
import java.util.*;
 
public class InternationalOlympiadV2{
   public static void main(String[] args) {
      MyScanner sc = new MyScanner();
      PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
      Problem problem = new Problem();
      problem.solve(sc, out);
      out.close();
   }
   
   public static class Problem {
	   public void solve(MyScanner sc, PrintWriter out){
		   int n = sc.nextInt();
		   String[] abbreviations = new String[n];
		   for (int i = 0; i < n ; i++){
			   String name = sc.nextLine();
			   String[] split = name.split("'");
			   abbreviations[i] = (split[1]);
		   }
		   
		   for (int i = 0; i < n ; i++){
			   out.println(getYear(abbreviations[i]));
		   }
	   }
	   
	   public String getYear(String s){
		   
		   //If the year is between the range 1989 - 1998 then simply take the first least significant digit
		   //Abbreviations 0-9
		   if (s.length() == 1){
			   if (Integer.parseInt(s) == 9){
				   return "1989";
			   }
			   else {
				   return "199" + Integer.parseInt(s);
			   }
		   }
		   //If the year is between the range 1999-2098 then take the two least significant digits
		   //Abbreviations 00-99
		   else if (s.length() == 2){
			   if (Integer.parseInt(s) == 99){
				   return "1999";
			   }
			   else {
				   return "20" + s;
			   }
		   }
		   //If the year is between the range 2099 - 3098 then take the three least significant digits
		   //Abbreviations 000-999
		   else if (s.length() == 3){
			   if (Integer.parseInt(s) == 99){
				   return "2099";
			   }
			   else if (Integer.parseInt(s) >= 100 && Integer.parseInt(s) <= 999){
				   return "2" + s;
			   }
			   else {
				   return "3" + s;
			   }
		   }
		   //If the year is between the range 3099 - 13098 then take the four least significant digits
		   //Abbreviations 0000-9999
		   else if (s.length() == 4){
			   if (Integer.parseInt(s) >= 3099){
				   return s;
			   }
			   else {
				   return "1" + s;
			   }
		   }
		   //If the year is between the range 13099 - 113098 then take the five least significant digits
		   //Abbreviations 00000-99999
		   else if (s.length() == 5){
			   if (Integer.parseInt(s) >= 13099){
				   return s;
			   }
			   else {
				   return "1" + s;
			   }
		   }
		   //If the year is between the range 113099 - 1113098 then take the six least significant digits
		   //Abbreviations 000000-999999
		   else if (s.length() == 6){
			   if (Integer.parseInt(s) >= 113099){
				   return s;
			   }
			   else {
				   return "1" + s;
			   }
		   }
		   //If the year is between the range 1113099 - 11113098 then take the seven least significant digits
		   //Abbreviations 0000000-9999999
		   else if (s.length() == 7){
			   if (Integer.parseInt(s) >= 1113099){
				   return s;
			   }
			   else {
				   return "1" + s;
			   }
		   }
		   //If the year is between the range 11113099 - 111113098 then take the eight least significant digits
		   //Abbreviations 00000000-99999999
		   else if (s.length() == 8){
			   if (Integer.parseInt(s) >= 11113099){
				   return s;
			   }
			   else {
				   return "1" + s;
			   }
		   }
		   //If the year is between the range 111113099 - 1111113098 then take the nine least significant digits
		   //Abbreviations 000000000-999999999
		   else if (s.length() == 9){
			   if (Integer.parseInt(s) >= 111113099){
				   return s;
			   }
			   else {
				   return "1" + s;
			   }
		   }
		   return null;
	   }
   }

   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      public String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      public int nextInt() {
          return Integer.parseInt(next());
      }
 
      public long nextLong() {
          return Long.parseLong(next());
      }
 
      public double nextDouble() {
          return Double.parseDouble(next());
      }
 
      public String nextLine(){
          String str = "";
          try {
        	  str = br.readLine();
          } catch (IOException e) {
        	  e.printStackTrace();
          }
          return str;
      }
   }
}