#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 510, M = 3 * N;
const int base = 1e9;
const int P = 131;
int n, m, t, k, x;
int a[N];
int st[N];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    int sum1 = 0, sum0 = 0;
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &st[i]);
      if (st[i] == 0)
        ++sum0;
      else
        ++sum1;
    }
    int flag = 1;
    for (int i = 1; i < n; ++i)
      if (a[i] > a[i + 1] && (sum0 == 0 || sum1 == 0)) {
        flag = 0;
        break;
      }
    if (flag == 0)
      printf("No\n");
    else
      printf("Yes\n");
  }
  return 0;
}
