Medium Recursion > Backtracking with Pruning/Branch and Bound

**BigMOD** is a ***very intelligent boy***. He likes mathematics and mathematical games. He often challenge his friends in various mathematical games. But all his friends are not good at mathematics and when **BigMOD** challenges his friends and they can’t answer the problem properly he feel very proud. But today his friend **LittleMOD** who is a great programmer challenge him to solve a problem like this: **LittleMOD** give him two integer number N and K and ask him ***"what is the maximum and minimum number can be get from N after deleting exactly K digits from N without changing the order of the digits?"*** Though **BigMOD** is good at mathematics but he is not good in programming and he wants to win this challenge so he wants your help to solve this problem. Can you help **BigMOD** to defeat **LittleMOD** in this game ? Input: ------ Input starts with an integer **(1<=T≤200)** which denotes the number of test case. Each test case consists of two integers N and Q **(0<=N<10^10 and 1<=Q<=100)** Where N is the given Number by **LittleMOD** and **Q** is the number of query. The next line contains Q space separated integers which denotes the value of **K ( 0<=K<=|N| )** Here **|N|** denotes the ***number of digits in N***. Output: ------- For each test case, print the case number at first. Then for each **K** given in query print the maximum and the minimum number without leading zeros which are the answer for **BigMOD** in the above game. In case of K=|N|, you should output a line with two zeros separated by a space. See the sample input and output for better understanding. Sample Input ------------ 2 1234 2 1 2 1578 1 3 Sample Output ------------- Case 1: 234 123 34 12 Case 2: 8 1

Tanmoy Tapos Datta