#include <bits/stdc++.h>
using namespace std;
const long long int N = 2e5 + 5;
void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  vector<int> one, two, b(n);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a == 1) {
      cnt++;
    }
  }
  if (cnt == n || cnt == 0) {
    vector<int> v2 = v;
    sort(v2.begin(), v2.end());
    if (v2 == v) {
      cout << "Yes"
           << "\n";
    } else {
      cout << "No"
           << "\n";
    }
  } else {
    cout << "Yes"
         << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  cin >> t;
  while (t--) solve();
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
  return 0;
}
