#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, flag = 0;
    cin >> n;
    int a[n], b[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] < a[i - 1] && i > 0) flag = 1;
    }
    for (int i = 0; i < n; i++) {
      cin >> b[i];
      if (b[i] != b[i - 1] && i > 0) flag = 0;
    }
    if (flag == 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}
