#include <bits/stdc++.h>
using namespace std;
struct elem {
  int x, y;
};
elem v[502];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t, l, n, i, ok, a, b, k;
  cin >> t;
  for (l = 1; l <= t; l++) {
    cin >> n;
    for (i = 1; i <= n; i++) cin >> v[i].x;
    for (i = 1; i <= n; i++) cin >> v[i].y;
    ok = 0;
    k = 0;
    for (i = 1; i <= n; i++)
      if (v[i].y == 0)
        k = 1;
      else
        ok = 1;
    if (ok == 1 && k == 1)
      cout << "Yes";
    else {
      ok = 1;
      for (i = 1; i < n; i++)
        if (v[i].x > v[i + 1].x) {
          ok = 0;
          break;
        }
      if (ok == 1)
        cout << "Yes";
      else
        cout << "No";
    }
    cout << '\n';
  }
  return 0;
}
