#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long int llINF = (long long)(1e18) + 100;
const int MAXN = 1e5 + 10;
const long long int mod = 1e9 + 7;
void solve() {
  int n, v[555];
  bool zr, um;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> v[i];
  zr = um = 0;
  int x;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x == 0)
      zr = 1;
    else
      um = 1;
  }
  bool ok = 1;
  for (int i = 0; i < n - 1; i++) {
    if (v[i] > v[i + 1]) ok = 0;
  }
  if (ok) {
    cout << "yes" << '\n';
    return;
  }
  if (zr and um)
    cout << "yes" << '\n';
  else
    cout << "no" << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
}
