import java.io.*;
import java.util.*;
import java.util.Map.Entry;

import static java.lang.Math.*;

public class Ans implements Runnable {

	public static void main(String args[]) {
		Ans s = new Ans();
		s.run();
	}

	static void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	InputReader sc = null;
	PrintWriter pw = null;
	
	private int getMax(int first, ArrayList<Integer> a){
		int maxi = 0, ele = 0;
		for(int n : a){			
			if(maxi < gcd(first, n)){
				maxi = gcd(first, n);
				ele = n;
			}
		}
		a.remove(new Integer(ele));
		return ele;
	}
	
	private int gcd(int a, int b){
		if(a == 0)
			return b;
		return gcd(b % a, a);
	}
	
	public void run() {

		// InputStream is;
		// is = new FileInputStream(new File("input.txt"));
		sc = new InputReader(System.in);
		pw = new PrintWriter(System.out);

		int T = sc.nextInt();
		while (T-- > 0) {			
			int n = sc.nextInt();
			ArrayList<Integer> a = new ArrayList<>();
			for(int i = 0; i <n ;i++){
				a.add(sc.nextInt());
			}
			Collections.sort(a, Collections.reverseOrder());
			if(n == 1){
				pw.println(a.get(0));
				continue;
			}
			int first = a.get(0);
			pw.print(first+" ");
			a.remove(new Integer(first));
			while(a.size() != 1){
				first = getMax(first,a);				
				pw.print(first +" ");								
			}			
			pw.println(a.get(0));
		}

		// is.close();
		pw.close();

	}

	static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[5];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}

				if (numChars <= 0)
					return -1;
			}

			return buf[curChar++];
		}

		public String nextLine() {
			BufferedReader br = new BufferedReader(new InputStreamReader(stream));
			String stock = "";
			try {
				stock = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return stock;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-') {
				sgn = -1;
				c = read();
			}

			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));

			return res * sgn;
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;

			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public double nextDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, nextInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, nextInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));

			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String next() {
			return readString();
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}
}