Problem H
 kuPellaKeS BST
Time Limit: 2 Seconds

 

A Binary Search Tree (BST) is a tree data structure, which obeys the following properties: A kuPellaKeS BST is a BST which have the following properties:

The following rules describe a representation way for a BST:

Given a list of integer numbers, output the representation of the kuPellaKeS BST having those numbers as node values.

Input
The first line of input gives the number of cases, T. Then, T test cases follow. Each one starts with a line containing number of values 1<=n<=1000. Next line contains n integer numbers separated by a single space.

Output
For the xth test case, your program must output the line containing "Case #x:", followed by representation of the kuPellaKeS BST having the given numbers as node values.

Sample Input
Sample Output
3
10
1 2 3 4 5 6 7 8 9 10
5
1 0 1 0 1
4
-1 -2 -3 -4
 
Case #1: 7(5(3(2(1),4),6),9(8,10))
Case #2: 1(1(1(0(0))))
Case #3: -3(-4,-2(-1))

Problem setter: Hadi Moshayedi

1st Amirkabir UT Annual Programming Contest  Final Round