#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n;
    int a[n], b[n];
    bool ok1 = false, ok2 = false, ok = true;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (i > 0) {
        if (a[i] < a[i - 1]) {
          ok = false;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      cin >> b[i];
      if (b[i] == 1) {
        ok1 = true;
      } else {
        ok2 = true;
      }
    }
    if (ok) {
      cout << "Yes" << endl;
    } else {
      if (ok1 && ok2) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
  }
}
