#include <bits/stdc++.h>
using namespace std;
const int CONST = 1e9 + 7;
const double pi = 3.14159265358979323846;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a, b;
    for (int i = 0; i < n; ++i) {
      int tmp;
      cin >> tmp;
      a.push_back(tmp);
    }
    int sum = 0;
    for (int i = 0; i < n; ++i) {
      int tmp;
      cin >> tmp;
      b.push_back(tmp);
      sum += tmp;
    }
    bool f = false;
    if (sum == n || sum == 0) {
      for (int i = 1; i < n; ++i) {
        if (a[i] < a[i - 1]) {
          f = true;
          break;
        }
      }
      if (!f)
        cout << "Yes" << endl;
      else
        cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }
  return 0;
}
