Prof. Z thinks his homework is very hard for most of his students to solve (do you remember the task “Boring Homework”?) To his surprise, many students hand in correct solutions. He thinks the reason is actually the small size of the data set he used to test students’ programs rather than the low difficulty of the homework task. He decides to give his students the same homework again, but with enormous test cases. Of course, his students think his homework becomes even more boring this time. They need your help again. For the ones who don’t know what homework Prof. Z. had given to his students last time: You’re asked to draw a graph of a binary search tree (BST). A binary search tree, which may sometimes also be called ordered or sorted binary tree, is a node-based binary tree data structure which has the following properties: The left subtree of a node contains only nodes with keys less than the node’s key. The right subtree of a node contains only nodes with keys greater than the node’s key. Both the left and right subtrees must also be binary search trees. —from Wikipedia Given a list of integer keys that should be inserted into the BST one by one orderly, we can form a unique BST. Moreover, Prof. Z wants the students to draw the graph of this BST. The rules to draw a graph of a BST are listed below:
2/3 The second line contains N distinct integers, each of which can be represented by a 32-bit signed integer. These numbers should be inserted into an empty BST one by one in the given order. The third line contains an integer M (M ≤ 5). M lines follow, each contains four integers, which are the row and column number of the top left corner, and the number of rows Ri and columns Ci of the required graph fragment, respectively. All the input integers will be positive and fit into a 32-bit signed integer, except Ri and Ci, which will be less than or equal to 200 and greater than 0. Output For each test case: Output the case number counting from 1 in the first line. Then M blocks follow, each contains Ri (or less, see next) lines. Each line should contain exactly Ci characters. Use space (ASCII 32) to fill in the blank. But if a line contains only whitespaces, this line should not be outputted. Output a blank line after each graph fragment. Sample Input 3 3 312 1 1153 6456132 1 1 1 8 10 10 2 6 7 4 5 3 1 9 10 8 2 1155 3655 Sample Output Case #1: +-o | o+ | o Case #2: +--o+ || o-+ o+ || +o o | o Case #3:
3/3 +o--- | o +- | +o+ o+ | o-+ | +o+