#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    vector<long long int> a(n);
    vector<long long int> b(n);
    bool flg0 = 0;
    bool flg1 = 0;
    bool flg = 0;
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
      if (i >= 1 && a[i] < a[i - 1]) {
        flg = 1;
      }
    }
    for (long long int i = 0; i < n; i++) {
      cin >> b[i];
      if (b[i] == 0) {
        flg0 = 1;
      }
      if (b[i] == 1) {
        flg1 = 1;
      }
    }
    if ((flg0 && flg1) || !flg) {
      cout << "Yes"
           << "\n";
    } else {
      cout << "No"
           << "\n";
    }
  }
}
