#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int MAX = 2e5 + 5;
void solve() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  bool op, zp;
  op = zp = false;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] == 1)
      op = true;
    else
      zp = true;
  }
  if (is_sorted(a.begin(), a.end()) || (op and zp)) {
    cout << "Yes";
  } else
    cout << "No";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int nov27;
  cin >> nov27;
  while (nov27--) {
    solve();
    cout << "\n";
  }
  return 0;
}
