import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class B
{
	private static void solve(FastScanner fr) {
		int n = fr.nextInt();
		Set<Integer> set = new HashSet<>();
		int max = 0;
		for(int i=0;i<n;i++) {
			int x = fr.nextInt();
			max = Math.max(max, x);
			set.add(x);
		}
		
		System.out.print(max+" ");
		set.remove(max);
		for(int i=2; i<=max/2; i++){
			if(max%i!=0) continue;			
			for(int j=max/i; j<max; j+=max/i){
				if(!set.contains(j)) continue;
				System.out.print(j+" ");
				set.remove(j);
			}
		}

		for(int k : set){
			System.out.print(k+" ");
		}
		sout();
	}
    public static void main(String[] args) {
		FastScanner fs = new FastScanner();
		// int n = 1;
		int n = fs.nextInt();
		while (n-- > 0)	{
			solve(fs);
        }
    }

    private static void sout()          { System.out.println();  }
    private static void sout(String s)  { System.out.println(s); }
    private static void sout(int s)     { System.out.println(s); }
    private static void sout(long s)    { System.out.println(s); }
    private static void sout(double s)  { System.out.println(s); }
    
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); }
			return st.nextToken();
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		int nextInt() {	return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
		double nextDouble() { return Double.parseDouble(next()); }
	}
}
