from math import gcd,sqrt
for _ in range(int(input())):
  n=int(input());arr=list(map(int,input().split()))
  maxx=max(arr);dp=[0]*(maxx+1);ans=[]
  for i in arr:
    dp[i]=1
  div=[];
  for i in range(1,int(sqrt(maxx))+1):
    if maxx%i==0:div.append(i);
    if maxx%i==0 and i!=(maxx//i) and maxx%(maxx//i)==0:div.append(maxx//i)
  div=sorted(div)[::-1]
 # print(div)
  for i in div:
   for j in range(maxx,i-1,-i):
    if dp[j]==1:ans.append(j);dp[j]=0
  print(*ans)
   
