#include <bits/stdc++.h>
using namespace std;
int main() {
  int r;
  cin >> r;
  while (r--) {
    long long n, i, j, k = 0, m, h = 0, t = 0, p, y;
    cin >> n;
    int a[n], b[n], c[n];
    for (i = 0; i < n; i++) {
      cin >> a[i];
      c[i] = a[i];
    }
    for (i = 0; i < n; i++) {
      cin >> b[i];
      if (b[i] == 1) {
        h++;
      } else
        t++;
    }
    sort(c, c + n);
    for (i = 0; i < n; i++) {
      if (a[i] == c[i]) {
        k++;
      } else
        break;
    }
    if (t > 0 && h > 0 || k == n) {
      cout << "Yes" << endl;
    } else
      cout << "No" << endl;
  }
  return 0;
}
