{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"Let S \u003d s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways:\r\u003cbr\u003eq\tBy an integer sequence P \u003d p1 p2...pn where pi is the number of left parentheses before the ith right parenthesis in S (P-sequence).\r\u003cbr\u003eq\tBy an integer sequence W \u003d w1 w2...wn where for each right parenthesis, say a in S, we associate an integer which is the number of right parentheses counting from the matched left parenthesis of a up to a. (W-sequence).\r\u003cbr\u003e\r\u003cbr\u003eFollowing is an example of the above encodings:\r\u003cbr\u003e\u003cpre\u003e\r\u003cbr\u003e\tS\t\t(((()()())))\r\u003cbr\u003e\tP-sequence\t 4 5 6666\r\u003cbr\u003e\tW-sequence\t 1 1 1456\r\u003cbr\u003e\u003c/pre\u003e\r\u003cbr\u003eWrite a program to convert P-sequence of a well-formed string to the W-sequence of the same string.\r\u003cbr\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line of the input contains a single integer t (1 \u0026lt;\u003d t \u0026lt;\u003d 10), the number of test cases, followed by the input data for each test case. The first line of each test case is an integer n (1 \u0026lt;\u003d n \u0026lt;\u003d 20), and the second line is the P-sequence of a well-formed string. It contains n positive integers, separated with blanks, representing the P-sequence."}},{"title":"Output","value":{"format":"HTML","content":"The output file consists of exactly t lines corresponding to test cases. For each test case, the output line should contain n integers describing the W-sequence of the string corresponding to its given P-sequence."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e2\r\n6\r\n4 5 6 6 6 6\r\n9 \r\n4 6 6 6 6 8 9 9 9\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1 1 1 4 5 6\r\n1 1 2 4 5 1 1 3 9\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}