#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    int a[n], b[n], zero = 0, one = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
      cin >> b[i];
      if (b[i]) {
        one = 1;
      } else {
        zero = 1;
      }
    }
    if (is_sorted(a, a + n)) {
      cout << "Yes" << endl;
    } else if (zero == 1 && one == 1) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}
