#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  long long int a[505];
  long long int b[505];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long int cnt1 = 0, cnt0 = 0;
  for (long long int i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i]) {
      cnt1++;
    } else {
      cnt0++;
    }
  }
  if (cnt1 == 0 || cnt0 == 0) {
    bool ans = true;
    for (long long int i = 0; i < n - 1; i++) {
      if (a[i + 1] < a[i]) {
        ans = false;
        break;
      }
    }
    if (ans) {
      cout << "Yes"
           << "\n";
    } else {
      cout << "No"
           << "\n";
    }
  } else {
    cout << "Yes"
         << "\n";
  }
}
int32_t main() {
  long long int t = 1;
  scanf("%lld", &t);
  for (long long int i = 0; i < t; i++) {
    solve();
  }
  cerr << "\n"
       << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms"
       << '\n';
  return 0;
}
