#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 7;
const int N = 1e6 + 1000;
const int M = 2000;
const double EPS = 1 / 1e10;
const long long HESH = 73;
const long long MAX_H = 1e5;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& p) {
  in >> p.first >> p.second;
  return in;
}
int a[N];
vector<int> v;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(3);
  int q;
  cin >> q;
  while (q--) {
    int n, j1 = 0, j2 = 0, b;
    cin >> n;
    v.clear();
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) {
      cin >> b;
      if (b)
        j1++;
      else
        j2++;
      v.push_back(a[i]);
    }
    int k = 1;
    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++)
      if (v[i] != a[i]) k = (j1 && j2);
    if (k)
      cout << "Yes\n";
    else
      cout << "No\n";
  }
  return 0;
}
