#include <bits/stdc++.h>
using namespace std;
int n, num[100007], tol[100007];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    int m = 1000000007;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &num[i]);
      tol[i] = num[i];
      m = ((m) < (num[i]) ? (m) : (num[i]));
    }
    sort(num + 1, num + n + 1);
    int flag = 1;
    for (int i = 1; i <= n; i++) {
      if (num[i] != tol[i] && num[i] % m > 0) {
        flag = 0;
        break;
      }
    }
    if (flag)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
