#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(time(0));
  ;
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    pair<int, int> p[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    int z = 0;
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      p[i] = {a[i], x};
      if (x == 0) z++;
    }
    sort(a, a + n);
    int i = 0;
    for (i = 0; i < n; i++) {
      if (a[i] != p[i].first) break;
    }
    if (i == n) {
      cout << "yes\n";
      continue;
    }
    if (z == n || z == 0)
      cout << "no\n";
    else
      cout << "yes\n";
  }
}
