#include <bits/stdc++.h>
using namespace std;
long long a[100010], b[100010];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    int flag = 1;
    long long min = 1e9 + 1;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      b[i] = a[i];
      if (min > a[i]) min = a[i];
    }
    sort(b, b + n);
    for (int i = 0; i < n; i++) {
      if (a[i] != b[i]) {
        if (a[i] % min != 0) {
          flag = 0;
          break;
        }
      }
    }
    if (flag)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
