#include <bits/stdc++.h>
using namespace std;
bool sortinrev(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return (a.first > b.first);
}
void solve() {
  long long n;
  cin >> n;
  vector<pair<long long, long long>> v;
  long long a[n], b[n];
  long long flag = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    v.push_back({a[i], i});
  }
  long long flag1 = 0, flag0 = 0;
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] == 0)
      flag0++;
    else
      flag1++;
  }
  if (flag1 > 0 && flag0 > 0) {
    cout << "Yes"
         << "\n";
    return;
  }
  sort(v.begin(), v.end());
  for (long long i = 0; i < n; i++) {
    if (v[i].first != a[i]) flag = 1;
  }
  if (flag == 0)
    cout << "Yes"
         << "\n";
  else
    cout << "No"
         << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
