#include <bits/stdc++.h>
using namespace std;
long long t = 1, MOD = 1e9 + 7;
template <class myType>
void print_arr(myType &arr, long long L, string sep) {
  for (long long(i) = (0); (i) < (L); ++(i)) {
    cout << arr[i];
    if (i < L - 1) cout << sep;
  }
  cout << "\n";
  return;
}
void solve() {
  int n;
  cin >> n;
  int a[n], b[n];
  for (long long(i) = (0); (i) < (n); ++(i)) cin >> a[i];
  for (long long(i) = (0); (i) < (n); ++(i)) cin >> b[i];
  int x = 0;
  for (long long(i) = (0); (i) < (n); ++(i)) x += b[i];
  string s = "Yes";
  if (x != 0 && x != n) {
    cout << s << "\n";
    return;
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (b[i] != b[j]) continue;
      if (a[i] > a[j]) s = "No";
    }
  }
  cout << s << "\n";
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> t;
  while (t--) solve();
  return 0;
}
