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