#include <bits/stdc++.h>
using namespace std;
string solve(int n, vector<int> a, vector<int> b) {
  bool flag = true;
  for (int i = 1; i < n; i++) {
    if (a[i] < a[i - 1]) {
      flag = false;
      break;
    }
  }
  if (flag == true) return "Yes";
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (b[i] == 0) cnt++;
  }
  if (cnt == 0 || cnt == n) return "No";
  return "Yes";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n + 1);
    vector<int> b(n + 1);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
      cin >> b[i];
    }
    cout << solve(n, a, b) << endl;
  }
  return 0;
}
