#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a;
  cin >> a;
  while (a--) {
    int n;
    cin >> n;
    int arr[n], brr[n], soi[n], zer = 0, one = 0;
    for (int i = 0; i < n; i++) cin >> arr[i];
    for (int i = 0; i < n; i++) cin >> brr[i];
    for (int i = 0; i < n; i++) soi[i] = arr[i];
    sort(soi, soi + n);
    for (int i = 0; i < n; i++) {
      if (brr[i] == 0)
        zer++;
      else
        one++;
      if (zer > 0 && one > 0) break;
    }
    if (zer > 0 && one > 0)
      cout << "Yes" << endl;
    else {
      int flag = 0;
      for (int i = 0; i < n; i++) {
        if (soi[i] != arr[i]) {
          flag = 1;
          break;
        }
      }
      if (flag == 0)
        cout << "Yes" << endl;
      else
        cout << "No" << endl;
    }
  }
  return 0;
}
