Quarter-Finals with Brazil!? No!!!

The FIFA World Cup of Germany 2006 is just going to start! This time, Spain cannot fail! We have to win the cup, even though we meet Brazil in quarter-finals . . . Now, seriously, everybody knows the “Canarinha” (Brazilian national football team) is the best team. But still we can play with statistics and probabilities. For example, the German organizers (that are not so good as Brazil but very clever people) have arranged the competition so that eventually Germany and Brazil could only meet in the final. Very clever, indeed. In this problem you will have to organize a Football World Cup, maximizing the probability that our team wins the cup. 2N teams participate in a cup competition with N rounds. The teams are denoted by A, B, C, D, etc. An arrangement of the competition is given by a string, e.g. “ABCD”, “BDAC” or “BA”. For example, the string “ABCDEFGH” means that in first round the matches are (A vs. B), (C vs. D), (E vs. F), . . ., in the second round (winner(A,B) vs. winner(C,D)), and so on. We have scored all the teams with integer positive numbers, s(x); the greater the better. For each pair of teams, A and B, we assume the probability that A beats B is given by the following: P (A wins B) = s(A)/(s(A) + s(B)) Using this basic probability, we can compute the probability that A wins one round, two rounds, three rounds, and eventually the probability to win the cup. For example, for the arrangement “ABCD” the probability that A wins the cup is: P(A wins ‘‘ABCD”) = P(A wins B)∗(P(A wins C)∗P(C wins D)+P(A wins D)∗P(D wins C)) You have to compute the arrangement that maximizes the probability that our team wins the cup. If more than one arrangement is possible, you have to give the alphabetically first one. Input The first line of the input contains an integer M, indicating the number of test cases. For each test case, the first line contains an integer N, between 1 and 5, indicating the number of rounds in the competition. The second line contains a single character, indicating the letter of our team. Then, we have a line with 2N integers indicating the scores of the teams, starting with A, that is: s(A), s(B), s(C), and so on. In the case N = 5, lowercase letters are used to denote the teams form 27 to 32; and those letters are considered to be alphabetically greater than uppercase letters. That is, the teams in order are: A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, a, b, c, d, e, f. Output For each test case, the output should consist of a string with 2N characters, representing the desired arrangement. Remember that you have to output the alphabetically first possibility, if the solution is not unique. Sample Input 3 2 A 7319

2/2 2 C 44 44 44 44 3 E 89897898 Sample Output ACBD ABCD ABDGCEFH