# __author__ = "Vatsal Mistry" # A solution for FOREGONE SOLUTION Problem from Qualifier Round of Google's CodeJam 2019. # Problem Description Link : https://codingcompetitions.withgoogle.com/codejam/round/0000000000051705/0000000000088231 # Importing regular expression module. import re # tc holds the number of testcases. tc = int(input()) # A loop over tc i.e. number of testcases. for i in range(tc): # N holds the input number. N = int(input()) # Converting the integer N into string N_str. N_str = str(N) # Defining an empty list index_list. index_list = list() # Looping over N_str for finding the indices of positions where the digit "4" occurs. # finditer method from re module is used. It returns the indices where match is found. for match in re.finditer("4", N_str): # Adding the indices to the index_list defined above. index_list.append(match.start()) # Creating a new empty list new_number_list. new_number_list = list() #The following block is the logic to create a new number with the rules that whereever there occurs a digit 4 in the original number there will be digit 1 in the new number, rest the digit will be 0. # Loop to create new number, each digit in list. for j in range(len(N_str)): if j not in index_list: new_number_list.append("0") else: new_number_list.append("1") # Converting the new number list into string. new_number = int("".join(new_number_list)) # Defining and assigning as per given condition in problem. A = new_number B = N - new_number # Printing result. print("Case #" + str(i+1) + ":" + " " + str(A) + " " + str(B))