Big Vova SOLUTION
Alexander is a notable software engineer. Today he chose to at last go out and play football, however with the principal hit he left a mark on the new Rolls-Royce of the affluent finance manager Big Vova. Vladimir has as of late opened a store on the mainstream online commercial center “Zmey-Gorynych”, and extends Alex an employment opportunity: on the off chance that he shows his programming abilities by illuminating an assignment, he’ll fill in as a cybersecurity master. Else, he’ll be conveying some far fetched items for the following two years.
You’re given n positive numbers a1,a2,… ,an. Utilizing every one of them precisely without a moment’s delay, you’re to make such succession b1,b2,… ,bn that arrangement c1,c2,… ,cn is lexicographically maximal, where ci=GCD(b1,… ,bi) – the best basic divisor of the main I components of b.
Alexander is truly terrified of the states of this straightforward undertaking, so he requests that you illuminate it.
A grouping an is lexicographically littler than a succession b if and just in the event that one of the accompanying holds:
a will be a prefix of b, however a≠b;
in the main position where an and b vary, the succession a has a littler component than the relating component in b.
Each test contains various experiments. The principal line contains the quantity of experiments t (1≤t≤103). Portrayal of the experiments follows.
The principal line of each experiment contains a solitary whole number n (1≤n≤103) — the length of the succession a.
The second line of each experiment contains n whole numbers a1,… ,a (1≤ai≤103) — the succession a.
It is ensured that the whole of n over all experiments doesn’t surpass 103.
For each experiment yield the appropriate response in a solitary line — the ideal grouping b. On the off chance that there are various answers, print any.
1 8 2 3
3 8 9
64 25 75 100 50
96 128 88 80 52 7
2 4 8 16 17
8 2 1 3
9 3 8
100 50 25 75 64
128 96 80 88 52 7
17 2 4 8 16
In the main experiment of the model, there are just two potential changes b — [2,5] and [5,2]: for the first c=[2,1], for the second one c=[5,1].
In the third experiment of the model, number 9 ought to be the first in b, and GCD(9,3)=3, GCD(9,8)=1, so the second number of b ought to be 3.
In the seventh experiment of the model, initial four numbers pairwise have a typical divisor (an intensity of two), yet none of them can be the first in the ideal stage b.