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