//转变思路,从求具体元素的一样,到求长度一样就行。一个元素从inArr里入栈,直接while
//看sk里和outArr一样的元素,有就add到ls里,因为是while,一直有一直弹出
//最后看长度。
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int C=Integer.parseInt(br.readLine());
for(int i=0;i<C;i++){
int N=Integer.parseInt(br.readLine());
Stack<Integer> sk= new Stack<>();
String[] tempArr0=br.readLine().split(" ");
int[] inArr=Arrays.copyOf(strToInt(tempArr0,N),N);
String[] tempArr1=br.readLine().split(" ");
int[] outArr=Arrays.copyOf(strToInt(tempArr1,N),N);
int startOut=0;
ArrayList<Integer> ls=new ArrayList<>();
for(int j=0;j<N;j++){
int A=inArr[j];
sk.push(A);
//原来A==outArr[startOut]
while(!sk.empty()&&startOut<N&&sk.peek()==outArr[startOut]){
ls.add(A);
sk.pop();
startOut++;
}
}
System.out.println(yesOrNo(outArr,ls));
}
}
public static int[] strToInt(String[]arr,int N){
int[] outArr=new int[N];
for(int i=0;i<N;i++){
outArr[i]=Integer.parseInt(arr[i]);
}
return outArr;
}
public static String yesOrNo(int[] outArr,ArrayList<Integer> ls){
if(outArr.length==ls.size()){
return "Yes";
}else{
return "No";
}
}
}