import java.util.*;
import java.lang.Math;
import java.io.* ;

public class Account {
	
	class Pair {
        int key ;
        int val ;
        
        Pair(int key ,int val) {
            this.key = key ;
            this.val = val ;
        }
        
        int getKey() {
        	return this.key ;
        }
        
        int getVal() {
        	return this.val ;
        }
    }
	
	public static void main (String[] args) {
		
//		Scanner sc= new Scanner(System.in) ;
		FastReader sc= new FastReader() ;
		StringBuilder res= new StringBuilder() ;
		int t= 1 ;  
		t= sc.nextInt() ;
		while(t-- > 0) {
			int n= sc.nextInt() ;
			ArrayList<Integer> lst = new ArrayList<>() ;
			ArrayList<Integer> ans = new ArrayList<>() ;
			for(int i=0 ;i<n ;i++) {
				int x= sc.nextInt() ;
				lst.add(x) ;
			}
			Collections.sort(lst ,Collections.reverseOrder());
			ans.add(lst.get(0)) ;
			int gcd= ans.get(0) ;
			lst.remove(0) ;
			while(lst.size() > 0) {
				int cur= -1 ,num= -1 ,in= -1 ;
				for(int i=0 ;i<lst.size() ;i++) {
					int y= gcd(lst.get(i) ,gcd) ;
					if(y > cur) {
						cur= y ;
						num= lst.get(i) ;
						in= i ;
					}
				}
				gcd= cur ;
				ans.add(lst.get(in)) ;
				lst.remove(in) ;
			}for(int x : ans) {
				res.append(x+" ") ;
			}
			res.append("\n") ;
		}
		System.out.print(res);
	}
	
	

	public static int gcd(int a, int b)
	{
	    if (b == 0)
	        return a;
	    return gcd(b, a % b);
	     
	}

	
	public static class FastReader {
        
		BufferedReader br;
        StringTokenizer st;
 
        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }
 
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                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());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
 
        int [] readintarray(int n) {
            int res [] = new int [n];
            for(int i = 0; i<n; i++)res[i] = nextInt();
            return res;
        }
        long [] readlongarray(int n) {
            long res [] = new long [n];
            for(int i = 0; i<n; i++)res[i] = nextLong();
            return res;
        }
    }	
	
}