#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cout << *it << " = " << a << "\n";
  err(++it, args...);
}
long long inf = 1e18;
long long mod = 1e9 + 7;
void jack() {
  long long i, j, k, x, y, z, a, b, c, var, n, m,
      ind1 = 0, ind2 = 0, ans = 0, flag = 0, limit1 = 0, limit2 = 0, limit3 = 0;
  string s = "Vivek";
  long long sum = 0;
  cin >> n;
  long long arr[n], brr[n];
  for (i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sum = 0;
  ans = 0;
  for (i = 0; i < n; i++) {
    cin >> brr[i];
    if (brr[i] == 0) {
      sum++;
    } else {
      ans++;
    }
  }
  if (ans > 0 && sum > 0) {
    cout << "Yes" << endl;
  } else {
    flag = 0;
    for (i = 0; i < n; i++) {
      for (j = i + 1; j < n; j++) {
        if (arr[j] < arr[i]) {
          flag = 1;
          break;
        }
      }
    }
    if (flag == 1) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long i, j, k, x, y, z, a, b, c, var, n, m,
      ind1 = 0, ind2 = 0, ans = 0, flag = 0, limit1 = 0, limit2 = 0, limit3 = 0;
  long long tt;
  cin >> tt;
  while (tt--) {
    jack();
  }
}
