#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  int count = 0;
  int temp1 = 0;
  int temp2 = 0;
  bool sorted = true;
  for (int &x : a) {
    cin >> x;
    temp2 = x;
    if (count > 0 && temp2 < temp1) {
      sorted = false;
    }
    temp1 = x;
    count++;
  }
  count = 0;
  bool same = true;
  for (int &x : b) {
    cin >> x;
    temp2 = x;
    if (count > 0 && temp2 != b[0]) same = false;
    count++;
  }
  if (sorted) {
    cout << "Yes\n";
    return;
  }
  if (same) {
    cout << "No\n";
  } else {
    cout << "Yes\n";
  }
}
