#include <bits/stdc++.h>
using namespace std;
const int _max = 550;
int a[_max];
int b[_max];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int shi = 0;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
      cin >> b[i];
    }
    for (int i = 0; i < n - 1; i++) {
      if (a[i] <= a[i + 1]) {
      } else {
        shi = 1;
      }
    }
    int he = 0;
    if (shi == 1) {
      for (int i = 0; i < n; i++) {
        if (b[i] == 0) {
          he++;
        }
      }
      if (he == n || he == 0) {
      } else {
        shi = 0;
      }
    }
    if (shi == 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}
