#include <bits/stdc++.h>
using namespace std;
struct node {
  long long nod, d;
  node(long long a, long long b) {
    nod = a;
    d = b;
  }
  bool operator<(const node &p) const { return p.d < d; }
};
long long Set(long long n, long long pos) { return n = n | (1LL << pos); }
long long reset(long long n, long long pos) { return n = n & ~(1LL << pos); }
bool check(long long n, long long pos) { return (bool)(n & (1LL << pos)); }
long long power(long long x, long long y) {
  long long res = 1;
  x = x;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long n;
long long arr[100005];
long long status[100005];
int main() {
  long long tes;
  scanf("%lld", &tes);
  for (long long cas = 1; cas <= tes; cas++) {
    scanf("%lld", &n);
    for (long long i = 1; i <= n; i++) {
      scanf("%lld", &arr[i]);
    }
    bool f1 = 0;
    bool f2 = 0;
    for (long long i = 1; i <= n; i++) {
      scanf("%lld", &status[i]);
      if (status[i] == 0) f1 = 1;
      if (status[i] == 1) f2 = 1;
    }
    if (f1 && f2) {
      printf("Yes\n");
      continue;
    }
    bool f = 0;
    for (long long i = 1; i <= n - 1; i++) {
      if (arr[i] > arr[i + 1]) {
        f = 1;
        break;
      }
    }
    if (f) {
      printf("No\n");
    } else {
      printf("Yes\n");
    }
  }
  return 0;
}
