#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, n, k, t;
  cin >> t;
  while (t--) {
    cin >> n;
    int a[n], b[n];
    for (i = 0; i < n; i++) cin >> a[i];
    for (i = 0; i < n; i++) b[i] = a[i];
    sort(a, a + n);
    for (i = 0; i < n; i++)
      if (b[i] % a[0] != 0 and a[i] != b[i]) {
        cout << "No" << endl;
        goto th;
      }
    cout << "Yes" << endl;
  th:;
  }
}
