#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  int T;
  cin >> T;
  while (T--) {
    int n, a[550];
    bool b[550];
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    bool l = 0, k = 0;
    for (int i = 1; i <= n; i++) {
      cin >> b[i];
      if (b[i]) l = 1;
      if (!b[i]) k = 1;
    }
    if (l && k)
      cout << "YES";
    else if (l || k) {
      if (is_sorted(a + 1, a + n + 1))
        cout << "YES";
      else
        cout << "NO";
    }
    cout << endl;
  }
  return 0;
}
