{"trustable":false,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027$$$$$$\u0027, right: \u0027$$$$$$\u0027, display: true},\n {left: \u0027$$$\u0027, right: \u0027$$$\u0027, display: false},\n {left: \u0027$$\u0027, right: \u0027$$\u0027, display: true},\n {left: \u0027$\u0027, right: \u0027$\u0027, display: false}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003e An array G is constructed from an array A of length n as follows : \u003cbr /\u003e\ng\u003csub\u003ei\u003c/sub\u003e is the GCD of (A\u003csub\u003e1\u003c/sub\u003e, A\u003csub\u003e2\u003c/sub\u003e, ...., A\u003csub\u003ei\u003c/sub\u003e) for every 1 \u003c\u003d i \u003c\u003d n.\u003cbr /\u003e\nSo, the array G will be of the same length as the array A, and each element in it will be the prefix GCD of the array A up to the element\u0027s index. \u003c/p\u003e\n\n\u003cp\u003eGiven an array of n numbers, find any rearrangement of the given array which has the lexicographically maximum corresponding array G.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003e There are multiple test cases. The first line of input contains t, the number of test cases. 1 \u003c\u003d t \u003c\u003d 10\u003csup\u003e3\u003c/sup\u003e. Each test case consists of two lines.\u003c/p\u003e\n\n\u003cp\u003e\nThe first line of each test case contains the size of the array n, 1 \u003c\u003d n \u003c\u003d 10\u003csup\u003e3\u003c/sup\u003e. The second line of each test case contains the elements of the array.\n\u003c/p\u003e\n\n\u003cp\u003e\nIt is guaranteed that the summation of all n over all test cases does not exceed 10\u003csup\u003e3\u003c/sup\u003e.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eFor each test case output the answer in a single line \u0026nbsp;— the optimal rearrangement. If there are multiple answers, print any.\u003c/p\u003e"}},{"title":"Sample 1","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\u003e7\n2\n2 5\n4\n1 8 2 3\n3\n3 8 9\n5\n64 25 75 100 50\n1\n42\n6\n96 128 88 80 52 7\n5\n2 4 8 16 17\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e5 2 \n8 2 1 3 \n9 3 8 \n100 50 25 75 64 \n42 \n128 96 80 88 52 7 \n17 2 4 8 16 \n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eIn the first test case of the example, there are only two possible rearrangements \u0026nbsp;— [2, 5] and [5, 2]: for the first one G\u003d[2, 1], for the second one G\u003d[5, 1].\u003c/p\u003e\n\u003cp\u003eIn the third test case of the example, number 9 should be the first in the rearrangement, and GCD(9, 3)\u003d3, GCD(9, 8)\u003d1, so the second number of the rearrangement should be 3.\u003c/p\u003e\n\u003cp\u003eIn the seventh test case of the example, first four numbers pairwise have a common divisor (a power of two), but none of them can be the first in the optimal rearrangement.\u003c/p\u003e"}}]}