public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
while (T>0){
T--;
int n = in.nextInt();
int[] a = new int[n];
int[] b = new int[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
}
for (int i = 0; i < n; i++) {
b[i] = in.nextInt();
}
int k = 0;
int preNum = -1;
boolean flag = true;
//尝试升序
while(k<n){
if(a[k]<preNum && b[k]<preNum){
flag = false;
break;
}
if(a[k]<b[k]){
if(a[k]>=preNum){
preNum = a[k];
}else{
preNum = b[k];
}
}else {
if(b[k]>=preNum){
preNum = b[k];
}else {
preNum = a[k];
}
}
k++;
}
if (flag){
System.out.println("YES");
continue;
}else{
//尝试降序
flag = true;
preNum = Integer.MAX_VALUE;
k=0;
while(k<n){
if(a[k]>preNum && b[k]>preNum){
flag = false;
break;
}
if(a[k]>b[k]){
if(a[k]<=preNum){
preNum = a[k];
}else{
preNum = b[k];
}
}else {
if(b[k]<=preNum){
preNum = b[k];
}else {
preNum = a[k];
}
}
k++;
}
if(flag){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
}