#include <bits/stdc++.h>
using namespace std;
void swap(int arr[], int type[], int a, int b) {
  int temp;
  temp = arr[a];
  arr[a] = arr[b];
  arr[b] = temp;
  temp = type[a];
  type[a] = type[b];
  type[b] = temp;
}
int main() {
  int t, n, arr[505], type[505], temp, ind, minn;
  cin >> t;
  for (int q = 0; q < t; q++) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    for (int i = 0; i < n; i++) {
      cin >> type[i];
    }
    int f = 0;
    for (int i = 0; i < n; i++) {
      minn = INT_MAX;
      for (int j = i; j < n; j++) {
        if (arr[j] < minn) {
          minn = arr[j];
          ind = j;
        }
      }
      if (type[ind] != type[i] || ind == i) {
        swap(arr, type, ind, i);
      } else {
        for (int j = 0; j < n; j++) {
          if (type[j] != type[i]) {
            swap(arr, type, ind, i);
            break;
          }
          if (j == n - 1) {
            cout << "No\n";
            f++;
          }
        }
        if (f != 0) break;
      }
    }
    if (f != 0) continue;
    cout << "Yes\n";
  }
  return 0;
}
