#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  for (; t > 0; t--) {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    bool fl1 = true, fl2 = true;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (i != 0 && a[i] < a[i - 1]) fl1 = false;
    }
    for (int i = 0; i < n; i++) {
      cin >> b[i];
      if (b[i] != b[0]) fl2 = false;
    }
    if (fl2 && !fl1)
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  }
  return 0;
}
