#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e2 + 10;
const long long mod = 1e9 + 7;
struct po {
  int va, tp;
};
po in[maxn], cop[maxn];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, s1 = -1, s2 = -1;
    scanf("%d", &n);
    bool v0 = false, v1 = false, ok = true;
    for (int i = 0; i < n; ++i) {
      scanf("%d", &in[i].va);
    }
    for (int i = 0; i < n; ++i) {
      scanf("%d", &in[i].tp);
    }
    for (int j = 0; j < n; ++j) {
      if (!v0 && in[j].tp == 0) {
        v0 = true;
        s1 = in[j].va;
      } else if (!v1 && in[j].tp == 1) {
        v1 = true;
        s2 = in[j].va;
      }
    }
    for (int k = 0; k < n; ++k) {
      if (in[k].tp == 0) {
        if (in[k].va >= s1)
          s1 = in[k].va;
        else {
          ok = false;
          break;
        }
      } else {
        if (in[k].va >= s2)
          s2 = in[k].va;
        else {
          ok = false;
          break;
        }
      }
    }
    if (ok || (v0 && v1)) {
      printf("Yes\n");
    } else
      printf("No\n");
  }
}
