n,*a=$<.read.split.map &:to_i (1..n).map{|i|e=a[i-1];a[i,n]=a[i,n].sort{|x,y|z=e.lcm(x)<=>e.lcm(y);z==0?x<=>y:z}} $><