#include <bits/stdc++.h>
using namespace std;
struct node {
  int a, b;
} p[502];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &p[i].a);
    for (int i = 1; i <= n; i++) scanf("%d", &p[i].b);
    int c = 0, d = 0;
    for (int i = 1; i <= n; i++) {
      if (p[i].b == 0) c++;
      if (p[i].b == 1) d++;
    }
    if (c && d) {
      printf("Yes\n");
      continue;
    } else {
      int flag = 1;
      p[0].a = 0;
      for (int i = 1; i <= n; i++)
        if (p[i].a < p[i - 1].a) flag = 0;
      if (flag)
        printf("Yes\n");
      else
        printf("No\n");
    }
  }
  return 0;
}
