#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, r, p{0};
    bool ans = true;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> r;
      if (r < p) {
        ans = false;
      }
      p = r;
    }
    int c0{0}, c1{0};
    for (int i = 0; i < n; i++) {
      cin >> r;
      if (r) {
        c1++;
      } else {
        c0++;
      }
    }
    if (ans) {
      cout << "YES\n";
    } else if (c1 == 0 || c0 == 0) {
      cout << "NO\n";
    } else {
      cout << "YES\n";
    }
  }
  return 0;
}
