Alice and Bob are two friends. They want to buy two cars, one for Alice and one for Bob. That's why they come to a car shop. Alice wants to move faster. So, she wants to purchase the fastest car. On the other hand, Bob wants safety first. So, he wants to purchase the slowest car. They also want to spend the least money possible. So, if multiple cars are fulfilling their speed requirement, they will choose the one among them that has the lowest .
At first, there is no car in the shop. When a car arrives, its speed will be given. Let’s define, summation of each digit of and multiplication of ( each digit of ). For example, and .
The cars have based on the values of and where . If a car arrives and this is the only car in the shop then of the car is equal to the of the car. Otherwise, is the minimum absolute difference between the of the selected car and the other existing cars in the shop. of a car is defined as soon as the car arrives in the shop.
For example, if the of the cars existing in the shop are: and a car of is arrived, then the of the car will be: , as this is the minimum absolute difference between the of the car and the other existing cars in the shop.
You are given an integer . You have to perform total queries of types. They are:
Query type :
A new car arrives at the shop whose speed is
Query type :
Alice wants to purchase a car. Tell her the price of the car she will purchase.
Query type :
Bob wants to purchase a car. Tell him the price of the car he will purchase
Once Alice or Bob will purchase a car, that car will be removed from the shop. If there is no car to purchase output .
Input may contain several test cases. At first, you will be given an integer , the number of test cases.
Each test case will start with an integer , the number of queries. Then each query will follow. In the case of query type 1, you will be given an integer which is the speed of the car.
Constraints:
The summation of in all test cases will not exceed .
In each test case, at first print “Case :” in a separate line where is the case number starting from . Then for each query of types and , print the desired answer in a new line.
Input | Output |
---|---|
1 10 1 200 1 100 1 200 3 1 10 2 1 10 3 3 2 | Case 1: 4 0 0 4 6 |