#include <bits/stdc++.h>
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);
  int z;
  cin >> z;
  while (z--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = (0); i < (n); ++i) cin >> a[i];
    vector<int> b(n);
    vector<int> cnt(2);
    for (int i = (0); i < (n); ++i) {
      cin >> b[i];
      ++cnt[b[i]];
    }
    bool sorted = 1;
    for (int i = (1); i < (n); ++i)
      if (a[i - 1] > a[i]) sorted = 0;
    if (sorted) {
      cout << "Yes\n";
      continue;
    }
    if (cnt[0] > 0 and cnt[1] > 0)
      cout << "Yes\n";
    else
      cout << "No\n";
  }
}
