#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int a[N];
int b[N];
int c[N];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n;
    scanf("%d", &n);
    int mi = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      if (mi == 0) mi = a[i];
      mi = min(mi, a[i]);
      b[i] = a[i];
    }
    sort(b + 1, b + 1 + n);
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
      int x = a[i];
      int y = b[i];
      if (x != y) {
        c[++cnt] = x;
        c[++cnt] = y;
      }
    }
    int g = c[1];
    bool flag = false;
    for (int i = 2; i <= cnt; i++) {
      g = gcd(g, c[i]);
    }
    if (g % mi == 0 || cnt == 0)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
