#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  ;
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n], b[n];
    bool sorted = 1, have0 = 0, have1 = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (i >= 1 && a[i] < a[i - 1]) sorted = 0;
    }
    for (int i = 0; i < n; i++) {
      cin >> b[i];
      if (b[i] == 0)
        have0 = 1;
      else if (b[i] == 1)
        have1 = 1;
    }
    if (sorted)
      cout << "Yes\n";
    else if (have0 && have1)
      cout << "Yes\n";
    else
      cout << "No\n";
  }
  return 0;
}
