#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  unsigned long long t;
  cin >> t;
  while (t--) {
    unsigned long long n;
    cin >> n;
    unsigned long long a[n];
    unsigned long long b[n];
    unsigned long long sorted[n];
    unsigned long long one = 0;
    unsigned long long zero = 0;
    for (unsigned long long i = 0; i < n; i++) {
      cin >> a[i];
      sorted[i] = a[i];
    }
    for (unsigned long long i = 0; i < n; i++) {
      cin >> b[i];
      if (b[i] == 0)
        zero++;
      else
        one++;
    }
    sort(sorted, sorted + n);
    bool check = true;
    for (unsigned long long i = 0; i < n; i++) {
      if (sorted[i] != a[i]) {
        check = false;
        break;
      }
    }
    if (!check && (one == 0 || zero == 0))
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  }
  return 0;
}
