#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, t;
  cin >> t;
  for (k = 0; k < t; k++) {
    int n;
    cin >> n;
    int data[n + 5];
    int typ[n + 5];
    int i, j;
    for (i = 0; i < n; i++) {
      cin >> data[i];
    }
    for (i = 0; i < n; i++) {
      cin >> typ[i];
    }
    int store = 0, flag = 0, hati = 0;
    for (i = 0; i < n; i++) {
      store = typ[0];
      if (typ[i] != store) {
        flag = 1;
        hati = 2;
      }
    }
    if (flag == 0) {
      int cnt = 0;
      for (i = 0; i < n - 1; i++) {
        if (data[i] <= data[i + 1]) {
          cnt++;
        }
      }
      if (cnt == (n - 1))
        cout << "Yes" << endl;
      else
        cout << "No" << endl;
    }
    if (flag == 1) {
      cout << "Yes" << endl;
    }
  }
  return 0;
}
