{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eLet S \u003d s1 s2 … s2n be a well-formed string of parentheses. S can be encoded in two different ways:\u003cbr\u003e\u003cul\u003e\u003cbr\u003e\u003cli\u003eBy 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).\u003c/li\u003e\u003cbr\u003e\u003cli\u003eBy 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).\u003c/li\u003e\u003cbr\u003e\u003c/ul\u003e\u003cbr\u003eFollowing is an example of the above encodings:\u003cbr\u003e\u003cpre\u003e\u003cbr\u003e\u0026nbsp;\u0026nbsp;S\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;(((()()())))\u003cbr\u003e\u0026nbsp;\u0026nbsp;P-sequence\u0026nbsp;\u0026nbsp; 4 5 6666\u003cbr\u003e\u0026nbsp;\u0026nbsp;W-sequence\u0026nbsp;\u0026nbsp; 1 1 1456\u003cbr\u003e\u003c/pre\u003e\u003cbr\u003eWrite a program to convert P-sequence of a well-formed string to the W-sequence of the same string.\u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line of the input file contains a single integer t (1 t 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 n 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.\u003cbr\u003e"}},{"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.\u003cbr\u003e"}},{"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\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}