/** A solution to the contest problem Time Travel. Written by Ross Byers 7/25/07
 *
 */
import java.io.*;
import java.util.*;

public class time 
{

    public static void main(String args[]) throws IOException
    {
    	Scanner fin = new Scanner(new File("time.in"));
    	int n = fin.nextInt();
    	for (int i = 0; i < n; i++)
    	{
    		double fuel = fin.nextDouble();
    		
    		// Find out the power of 5 we have of fuel.
    		double centuries = Math.log(fuel)/Math.log(5.0);
    		
    		// Truncate this value as it states to do in the problem 
    		// description.
    		int years = (int)(centuries * 100.0);
    		
    		// Determine the signed target year.
    		int target_year = 2007 - years;
    		
    		// Print out the numerical value of the year.
    		System.out.print(Math.abs(target_year));
    		
    		// Print out the proper era.
    		if (target_year >= 0)
    		{
    			System.out.println(" C.E.");
    		}
    		else
    		{
    			System.out.println(" B.C.");
    		}
    	}
    }
    
    
}