#include <bits/stdc++.h>
using namespace std;
bool isprime(int n) {
  if (n == 1) return false;
  if (n == 2) return true;
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
void answer(int f) {
  if (f) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  cout << endl;
}
long long int countSetBits(long long int n) {
  long long int count = 0;
  while (n) {
    count += n & 1;
    n >>= 1;
  }
  return count;
}
long long int factorial(long long int n) {
  n = n % 1000000007;
  return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
long long int FastExp(long long int a, long long int b) {
  long long int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return (ans % 1000000007);
}
int main() {
  int test = 1;
  cin >> test;
  while (test--) {
    long long int n, i, j;
    cin >> n;
    long long int a[n], b[n], c[n];
    vector<long long int> x, y;
    vector<pair<int, int> > v(n), u(n);
    for (i = 0; i < n; i++) {
      int x;
      cin >> x;
      v[i].first = x;
      u[i].first = x;
    }
    int z = 0, o = 0;
    for (i = 0; i < n; i++) {
      int x;
      cin >> x;
      if (x == 0)
        z++;
      else {
        o++;
      }
      v[i].second = x;
      u[i].second = x;
    }
    int f = 1;
    sort(u.begin(), u.end());
    for (i = 0; i < n; i++) {
      if (v[i].first != u[i].first) f = 0;
    }
    if (f == 0 && (o == 0 || z == 0))
      f = 0;
    else
      f = 1;
    answer(f);
  }
  return 0;
}
