#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int inf = 0x3f3f3f3f;
int arr[maxn];
int a[maxn];
int b[maxn];
int main() {
  ios::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      a[i] = arr[i];
    }
    int flag1 = 0, flag0 = 0, flag = 0;
    for (int i = 0; i < n; i++) {
      cin >> b[i];
      if (b[i])
        flag1 = 1;
      else
        flag0 = 1;
    }
    if (flag1 && flag0) flag = 1;
    sort(arr, arr + n);
    int p = 0;
    for (int i = 0; i < n; i++)
      if (arr[i] != a[i]) p = 1;
    if (p == 0 || flag == 1)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}
