#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    set<int> u;
    int n, i, j, y = 0, w, k = 0;
    cin >> n;
    int a[n], b[n], c[n];
    for (i = 0; i < n; i++) {
      cin >> a[i];
      c[i] = a[i];
    }
    for (i = 0; i < n; i++) {
      cin >> b[i];
      u.insert(b[i]);
    }
    sort(a, a + n);
    for (i = 0; i < n; i++) {
      if (a[i] == c[i]) y++;
    }
    if (u.size() > 1 || y == n)
      cout << "Yes";
    else
      cout << "No";
    cout << endl;
  }
  return 0;
}
