#include <bits/stdc++.h>
using namespace std;
int a[501];
int main() {
  int tc, n;
  scanf("%d", &tc);
  while (tc--) {
    scanf("%d", &n);
    bool nd = 1;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      if (i && a[i - 1] > a[i]) nd = 0;
    }
    int cnt[2] = {0, 0};
    for (int i = 0, j; i < n; i++) {
      scanf("%d", &j);
      cnt[j]++;
    }
    if (nd || (!nd && cnt[0] && cnt[1]))
      printf("Yes\n");
    else
      printf("No\n");
  }
  return 0;
}
