#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, i, n, m, p, f;
  cin >> t;
  while (t--) {
    vector<long long> a, b;
    map<long long, long long> x;
    cin >> n, p = 0, f = 0;
    for (i = 0; i < n; i++) {
      cin >> m;
      a.push_back(m);
      if (p > m) f = 1;
      p = m;
    }
    for (i = 0; i < n; i++) {
      cin >> m;
      x[m]++;
    }
    if (x[0] == 0 || x[1] == 0) {
      if (f == 1)
        cout << "No" << endl;
      else
        cout << "Yes" << endl;
    } else
      cout << "Yes" << endl;
  }
}
