#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y) {
  if (x == 0 && y == 0) return 1;
  if (x <= 1 && y != 0) return 0;
  if (y == 0) return 1;
  long long int ans = 1;
  while (y > 0) {
    if (y % 2) ans *= x;
    y = y / 2;
    x = x * x;
  }
  return ans;
}
void solve(vector<pair<int, int>> a, int n) {
  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j < n - i - 1; j++)
      if (a[j].first > a[j + 1].first) {
        if (a[j].second != a[j + 1].second)
          swap(a[j], a[j + 1]);
        else {
          cout << "No" << endl;
          return;
        }
      }
  }
  cout << "Yes" << endl;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n], b[n];
    int flag = 0;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) {
      cin >> b[i];
      if (b[0] != b[i]) {
        flag = 1;
      }
    }
    if (flag == 1) {
      cout << "Yes" << endl;
      continue;
    } else {
      int h = 0;
      for (int i = 1; i < n; i++) {
        if (a[i] >= a[i - 1])
          continue;
        else {
          h = 1;
          break;
        }
      }
      if (h == 0)
        cout << "Yes" << endl;
      else {
        cout << "No" << endl;
      }
    }
  }
  return 0;
}
