#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int sum = 0;
    int a[n], b[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) {
      cin >> b[i];
      sum += b[i];
    }
    if (sum > 0 && sum < n)
      cout << "Yes\n";
    else {
      bool ans = true;
      for (int i = 1; i < n; i++) ans &= a[i] >= a[i - 1];
      if (ans)
        cout << "Yes\n";
      else
        cout << "No\n";
    }
  }
  return 0;
}
