#include<cstdio>#include<iostream>#include<algorithm>#include<map>#include<cctype>#include<cstring>usingnamespace std;constint N =1e5+10;inlineintread(){int x =0;char ch =getchar();while(isdigit(ch)){
x =(x <<1)+(x <<3)+(ch ^48);
ch =getchar();}return x;}int a[N], b[N];/*
* if all elements can change with mi
* then for one element
* it can be changed to any position
* within no more than two operations
*
*/intgcd(int x,int y){return y ==0? x:gcd(y, x % y);}voidsolve(){int n =read();int mi =2e9;for(int i =0; i < n;++i){
b[i]= a[i]=read();
mi =min(mi, a[i]);}sort(b, b + n);int flag =1;for(int i =0; i < n;++i){if(a[i]!= b[i]&& a[i]% mi >0){
flag =0;break;}}if(flag)printf("YES\n");elseprintf("NO\n");}intmain(){int cases =read();while(cases--){solve();}return0;}