#include <bits/stdc++.h>
using namespace std;
template <typename T>
void setmax(T& x, T y) {
  x = max(x, y);
}
template <typename T>
void setmin(T& x, T y) {
  x = min(x, y);
}
const double PI = acos(-1.0);
const long long INF = 1e9 + 47;
const long long LINF = INF * INF;
mt19937 rng(58);
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = (0); i < (n); ++i) cin >> a[i];
    for (int i = (0); i < (n); ++i) cin >> b[i];
    bool ans = is_sorted(a.begin(), a.end());
    sort(b.begin(), b.end());
    ans |= b[0] != b.back();
    cout << (ans ? "Yes" : "No") << endl;
  }
  cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
  return 0;
}
