#include <bits/stdc++.h>
using namespace std;
void solve(int n, vector<pair<int, int>>& v) {
  int z = 0;
  int o = 0;
  int flag = 0;
  for (int i = 0; i < n - 1; i++) {
    if (v[i].first > v[i + 1].first) {
      flag = 1;
    }
    if (v[i].second == 0)
      z++;
    else
      o++;
  }
  if (v[n - 1].second == 0)
    z++;
  else
    o++;
  if (flag == 0) {
    cout << "YES" << endl;
    return;
  } else {
    if (z == 0 || o == 0) {
      cout << "NO" << endl;
    } else {
      cout << "YES" << endl;
    }
  }
}
int main() {
  int t;
  cin >> t;
  int n;
  while (t--) {
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<pair<int, int>> v;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
      cin >> b[i];
    }
    for (int i = 0; i < n; i++) {
      v.push_back({a[i], b[i]});
    }
    solve(n, v);
  }
  return 0;
}
