#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, cn = 0;
    cin >> n;
    vector<long long> a(n), b(n);
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (long long i = 0; i < n; i++) {
      cin >> b[i];
      cn += b[i];
    }
    if (cn < n && cn >= 1)
      cout << "YES";
    else {
      vector<long long> c(a);
      sort(c.begin(), c.end());
      if (a == c)
        cout << "YES";
      else
        cout << "NO";
    }
    cout << "\n";
  }
}
