import java.io.*;
import java.util.*;

public class B{
    public static void main(String[] args) {
        FastReader fs=new FastReader();
        PrintWriter out=new PrintWriter(System.out);
        int t=1;
        t=fs.nextInt();
        for(int i=1;i<=t;i++) {
        	B m=new B();
            m.solve(i,out,fs);
        }
        out.close();
    } 
    static int GCD(int a,int b){
        int max=Integer.max(a,b),min=Integer.min(a,b);
        if(max%min==0)return min;
        return GCD(min,max%min);
    }
    public void solve(int test,PrintWriter out,FastReader fs){
        int n=fs.nextInt();
        int a[]=fs.nextIntArray(n);
        Arrays.sort(a);
        ArrayList<Integer> list=new ArrayList<Integer>();
        int gcd=a[n-1];
        list.add(a[n-1]);
        a[n-1]=-1;
        for(int j=1;j<n;j++){
            int new_gcd=Integer.MIN_VALUE,max_in=-1;
            for(int i=0;i<n;i++){
                if(a[i]<0)continue;
                int temp=GCD(gcd,a[i]);
                if(new_gcd<temp){
                    max_in=i;
                    new_gcd=temp;
                }
            }
            list.add(a[max_in]);
            a[max_in]=-1;
            gcd=new_gcd;
        }
        for(int i:list){
            out.print(i+" ");
        }
        out.println();
    }
}
class FastReader{
    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 nextInt(){
        return Integer.parseInt(next());
    }
    long nextLong(){
        return Long.parseLong(next());
    }
    int[] nextIntArray(int n){
        int a[]=new int[n];
        for(int i=0;i<n;i++)a[i]=nextInt();
        return a;
    } 
    long[] nextLongArray(int n){
        long a[]=new long[n];
        for(int i=0;i<n;i++)a[i]=nextInt();
        return a;
    }
    char[] nextCharArray(){
        char a[]=next().toCharArray();
        return a;
    }
}