#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
void sleek() {
  long long n;
  cin >> n;
  long long a[n], b[n];
  long long o = 0, z = 0;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i])
      o++;
    else
      z++;
  }
  long long flag = 1;
  for (long long i = 1; i < n; i++) {
    if (a[i] < a[i - 1]) flag = 0;
  }
  if (flag || (o && z))
    cout << "Yes";
  else
    cout << "No";
  cout << "\n";
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) sleek();
}
