#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    int types[n];
    for (int i = 0; i < n; i++) cin >> types[i];
    int f = 0, oc = 0, zc = 0;
    for (int i = 0; i < n - 1; i++) {
      if (types[i] == 1)
        oc++;
      else
        zc++;
      if (arr[i] > arr[i + 1]) {
        f = 1;
      }
    }
    if (types[n - 1] == 1)
      oc++;
    else
      zc++;
    if (f == 0)
      cout << "Yes";
    else {
      if (oc > 0 && zc > 0)
        cout << "Yes";
      else
        cout << "No";
    }
    cout << endl;
  }
}
