#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> arr1(n);
  vector<int> arr2(n);
  for (int i = 0; i < n; i++) {
    cin >> arr1[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> arr2[i];
  }
  int flag1 = 1;
  for (int i = 1; i < n; i++) {
    if (arr1[i - 1] > arr1[i]) {
      flag1 = 0;
      break;
    }
  }
  int flag2 = 0, flag3 = 0;
  for (int i = 0; i < n; i++) {
    if (arr2[i] == 0) {
      flag2 = 1;
    } else {
      flag3 = 1;
    }
  }
  if (flag1 == 1)
    cout << "Yes";
  else {
    if (flag2 == 1 && flag3 == 1)
      cout << "Yes";
    else
      cout << "No";
  }
  cout << "\n";
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
