{"trustable":true,"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\u003eAlexander is a well-known programmer. Today he decided to finally go out and play football, but with the first hit he left a dent on the new Rolls-Royce of the wealthy businessman Big Vova. Vladimir has recently opened a store on the popular online marketplace \"Zmey-Gorynych\", and offers Alex a job: if he shows his programming skills by solving a task, he\u0027ll work as a cybersecurity specialist. Otherwise, he\u0027ll be delivering some doubtful products for the next two years.\u003c/p\u003e\u003cp\u003eYou\u0027re given $$$n$$$ positive integers $$$a_1, a_2, \\dots, a_n$$$. Using each of them \u003cspan class\u003d\"tex-font-style-bf\"\u003eexactly at once\u003c/span\u003e, you\u0027re to make such sequence $$$b_1, b_2, \\dots, b_n$$$ that sequence $$$c_1, c_2, \\dots, c_n$$$ is \u003cspan class\u003d\"tex-font-style-it\"\u003elexicographically maximal\u003c/span\u003e, where $$$c_i\u003dGCD(b_1,\\dots,b_i)$$$ - the greatest common divisor of the first $$$i$$$ elements of $$$b$$$. \u003c/p\u003e\u003cp\u003eAlexander is really afraid of the conditions of this simple task, so he asks you to solve it.\u003c/p\u003e\u003cp\u003eA sequence $$$a$$$ is lexicographically smaller than a sequence $$$b$$$ if and only if one of the following holds:\u003c/p\u003e\u003cul\u003e\u003cli\u003e $$$a$$$ is a prefix of $$$b$$$, but $$$a \\ne b$$$;\u003c/li\u003e\u003cli\u003e in the first position where $$$a$$$ and $$$b$$$ differ, the sequence $$$a$$$ has a smaller element than the corresponding element in $$$b$$$.\u003c/li\u003e\u003c/ul\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 10^3$$$). Description of the test cases follows.\u003c/p\u003e\u003cp\u003eThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^3$$$) \u0026nbsp;— the length of the sequence $$$a$$$.\u003c/p\u003e\u003cp\u003eThe second line of each test case contains $$$n$$$ integers $$$a_1,\\dots,a_n$$$ ($$$1 \\le a_i \\le 10^3$$$) \u0026nbsp;— the sequence $$$a$$$.\u003c/p\u003e\u003cp\u003eIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^3$$$.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eFor each test case output the answer in a single line \u0026nbsp;— the desired sequence $$$b$$$. If there are multiple answers, print any.\u003c/p\u003e"}},{"title":"Examples","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 permutations $$$b$$$ \u0026nbsp;— $$$[2, 5]$$$ and $$$[5, 2]$$$: for the first one $$$c\u003d[2, 1]$$$, for the second one $$$c\u003d[5, 1]$$$.\u003c/p\u003e\u003cp\u003eIn the third test case of the example, number $$$9$$$ should be the first in $$$b$$$, and $$$GCD(9, 3)\u003d3$$$, $$$GCD(9, 8)\u003d1$$$, so the second number of $$$b$$$ should be $$$3$$$.\u003c/p\u003e\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 permutation $$$b$$$.\u003c/p\u003e"}}]}