#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    int b[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
      cin >> b[i];
    }
    int one_cnt = 0;
    int zero_cnt = 0;
    for (int i = 0; i < n; i++) {
      if (b[i] == 1) {
        one_cnt++;
      } else {
        zero_cnt++;
      }
    }
    if (one_cnt > 0 && zero_cnt > 0) {
      cout << "Yes" << endl;
    } else {
      vector<int> v;
      for (int i = 0; i < n; i++) {
        v.push_back(a[i]);
      }
      int flag = 0;
      sort(v.begin(), v.end());
      for (int i = 0; i < n; i++) {
        if (v[i] != a[i]) {
          flag = 1;
          break;
        }
      }
      if (flag == 1) {
        cout << "No" << endl;
      } else {
        cout << "Yes" << endl;
      }
    }
  }
  return 0;
}
