#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const long double EPS = 1e-9;
const int N = 1000000005;
const long long NL = 1000000000000000005LL;
const int mod = 1e9 + 7;
const int mod1 = 1e9 + 9;
const int mod2 = 998244353;
inline bool sorted(vector<int> arr) {
  if (arr.size() == 0 || arr.size() == 1) return true;
  for (int i = 1; i < arr.size(); i++)
    if (arr[i - 1] > arr[i]) return false;
  return true;
}
inline void solve() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, cntZ = 0, cntO = 0;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
    (b[i] == 0) ? cntZ++ : cntO++;
  }
  if (sorted(a)) {
    cout << "Yes"
         << "\n";
  } else {
    if (cntO > 0 && cntZ > 0) {
      cout << "Yes"
           << "\n";
    } else {
      cout << "No"
           << "\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
