#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6;
int b[N];
int a[N];
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    cnt += b[i];
  }
  if (cnt == 0 or cnt == n) {
    int lst0 = 0;
    int lst1 = 0;
    bool can = true;
    for (int i = 1; i <= n; i++) {
      if (b[i] == 0) {
        if (a[i] < lst0) can = false;
        lst0 = a[i];
      } else {
        if (a[i] < lst1) can = false;
        lst1 = a[i];
      }
    }
    if (can)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
