#include <bits/stdc++.h>
int main() {
  int cas;
  scanf("%d", &cas);
  while (cas--) {
    int n;
    scanf("%d", &n);
    std::vector<int> a(n);
    std::set<int> bs;
    for (int i = 0; i < n; ++i) {
      scanf("%d", &a[i]);
    }
    for (int i = 0; i < n; ++i) {
      int b;
      scanf("%d", &b);
      bs.emplace(b);
    }
    auto f = [](const std::vector<int>& v) -> bool {
      for (int i = 0; i + 1 < v.size(); ++i)
        if (v[i] > v[i + 1]) return false;
      return true;
    };
    puts(f(a) || bs.size() > 1 ? "YES" : "NO");
  }
}
