#include <bits/stdc++.h>
using namespace std;
struct ele {
  long long a, b;
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    struct ele arr[n];
    bool issorted = true, zer0 = false, one = false;
    for (long long i = 0; i < n; i++) {
      cin >> arr[i].a;
      if (i > 0 && arr[i].a < arr[i - 1].a) issorted = false;
    }
    for (long long i = 0; i < n; i++) {
      cin >> arr[i].b;
      if (arr[i].b == 1)
        one = true;
      else
        zer0 = true;
    }
    if (issorted)
      cout << "Yes"
           << "\n";
    else if (one && zer0)
      cout << "Yes"
           << "\n";
    else
      cout << "No"
           << "\n";
  }
  return 0;
}
