#include <bits/stdc++.h>
using namespace std;
const int m = 1e9 + 7;
bool isSorted(int *a, int n) {
  for (int i = 1; i < n; i++)
    if (a[i] < a[i - 1]) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int *a = new int[n];
    int *b = new int[n];
    bool one = false, zero = false;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) {
      cin >> b[i];
      if (b[i])
        one = true;
      else
        zero = true;
    }
    if (one and zero)
      cout << "Yes";
    else if (isSorted(a, n))
      cout << "Yes";
    else
      cout << "No";
    cout << "\n";
  }
}
