#include <bits/stdc++.h>
using namespace std;
int a[510], b[510];
int main() {
  int T;
  int n;
  int tag;
  bool flag;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    tag = 0;
    flag = true;
    for (int i = 0; i < n; i++) scanf("%d", a + i);
    for (int i = 0; i < n; i++) {
      scanf("%d", b + i);
      tag |= 1 << b[i];
    }
    for (int i = 1; i < n; i++) {
      if (a[i] < a[i - 1]) flag = false;
    }
    if (flag || tag == 3) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}
