#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> v(n);
    vector<long long> copy(n);
    for (long long i = 0; i < n; i++) {
      cin >> v[i];
      copy[i] = v[i];
    }
    vector<long long> t(n);
    long long ones = 0, zero = 0;
    for (long long i = 0; i < n; i++) {
      cin >> t[i];
      if (!t[i])
        zero++;
      else
        ones++;
    }
    sort(copy.begin(), copy.end());
    long long ans = 1;
    for (long long i = 0; i < n; i++) {
      if (v[i] != copy[i]) ans = 0;
    }
    if (ans) {
      cout << "Yes" << endl;
      continue;
    }
    int h = min(zero, ones);
    if (h >= 1) {
      cout << "Yes" << endl;
    } else
      cout << "No" << endl;
  }
  return 0;
}
