#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int n, x;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int zero = 0, one = 0;
    for (int i = 0; i < n; i++) {
      cin >> x;
      if (x)
        one++;
      else
        zero++;
    }
    vector<int> b;
    b = a;
    sort(b.begin(), b.end());
    if (a == b) {
      cout << "Yes\n";
    } else {
      if (zero == 0 || one == 0) {
        cout << "No\n";
      } else
        cout << "Yes\n";
    }
  }
}
