#include <bits/stdc++.h>
using namespace std;
const long long int MAX_N = 1e5 + 5;
const long long int mod = 1e9 + 7;
int a[MAX_N];
int b[MAX_N];
void love() {
  int n;
  cin >> n;
  int flag = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (flag != b[i] && flag != 3) {
      if (flag != -1) {
        flag = 3;
        continue;
      }
      flag = b[i];
    }
  }
  if (flag == 3) {
    cout << "Yes";
    return;
  }
  for (int i = 1; i < n; i++) {
    if (a[i - 1] > a[i]) {
      cout << "No";
      return;
    }
  }
  cout << "Yes";
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    love();
    cout << endl;
  }
  return 0;
}
