#include <bits/stdc++.h>
using namespace std;
int t, n;
int a[100010], b[100010];
int ok;
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    int num = 0;
    for (register int i = 1; i <= n; ++i) cin >> a[i];
    for (register int j = 1; j <= n; ++j) cin >> b[j], num += b[j];
    int ok = 1;
    for (register int i = 1; i <= n - 1; ++i)
      if (a[i] > a[i + 1]) {
        ok = 0;
        break;
      }
    if (num == 0 || num == n) {
      if (ok == 0)
        puts("NO");
      else
        puts("YES");
    } else
      puts("YES");
  }
  return 0;
}
