#include <bits/stdc++.h>
char *fs, *ft, buf[1 << 20];
inline int read() {
  int x = 0, f = 1;
  char ch =
      (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 20, stdin), fs == ft))
          ? 0
          : *fs++;
  ;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = (fs == ft &&
          (ft = (fs = buf) + fread(buf, 1, 1 << 20, stdin), fs == ft))
             ? 0
             : *fs++;
    ;
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = (fs == ft &&
          (ft = (fs = buf) + fread(buf, 1, 1 << 20, stdin), fs == ft))
             ? 0
             : *fs++;
    ;
  }
  return x * f;
}
using namespace std;
int a[1009];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    int z0 = 0, z1 = 0, bo = 0;
    cin >> n;
    cin >> a[1];
    for (int i = 2; i <= n; i++) {
      cin >> a[i];
      if (a[i] < a[i - 1]) bo = 1;
    }
    for (int i = 1; i <= n; i++) {
      int k;
      cin >> k;
      if (k == 0)
        z0++;
      else
        z1++;
    }
    if (bo == 0) {
      cout << "Yes" << endl;
      continue;
    } else {
      if (z0 == 0 || z1 == 0)
        cout << "No" << endl;
      else
        cout << "Yes" << endl;
    }
  }
  return 0;
}
