#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  return a * b / gcd(a, b);
}
int main() {
  ios_base::sync_with_stdio(false);
  long long int t;
  cin >> t;
  for (long long int i = 0; i < t; i++) {
    long long int n;
    cin >> n;
    long long int a[2][n];
    for (long long int j = 0; j < n; j++) {
      cin >> a[0][j];
    }
    for (long long int j = 0; j < n; j++) {
      cin >> a[1][j];
    }
    long long int z = 0, o = 0, b;
    for (long long int j = 0; j < n; j++) {
      if (a[1][j] == 0) {
        z = 1;
        break;
      }
    }
    for (long long int j = 0; j < n; j++) {
      if (a[1][j] == 1) {
        o = 1;
        break;
      }
    }
    b = z * o;
    if (b) {
      cout << "YES" << endl;
      continue;
    } else {
      b = 1;
      for (long long int k = 0; k < n - 1; k++) {
        if (a[0][k] > a[0][k + 1]) {
          b = 0;
        }
      }
    }
    if (b) {
      cout << "YES" << endl;
      continue;
    } else {
      cout << "NO" << endl;
      continue;
    }
  }
}
