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