#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int i;
    vector<pair<int, int>> vp(n);
    int count0 = 0, count1 = 0;
    bool flag = false;
    for (i = 0; i < n; i++) {
      cin >> vp[i].first;
      if (i > 0) {
        if (vp[i].first < vp[i - 1].first) {
          flag = true;
        }
      }
    }
    for (i = 0; i < n; i++) {
      cin >> vp[i].second;
      if (vp[i].second == 0) {
        count0++;
      } else {
        count1++;
      }
    }
    if (flag) {
      if (count0 > 0 && count1 > 0) {
        cout << "Yes\n";
      } else {
        cout << "No\n";
      }
    } else {
      cout << "Yes\n";
    }
  }
  return 0;
}
