#include<iostream>
#include<stack>
using namespace std;
stack<int>n;
int pushed[100005];
int poped[100005];
int main()
{
int cnt;
cin >> cnt;
while (cnt--)
{
int i = 0, j = 0;
int num;
cin >> num;
int tmp = num;
while (num--)
{
cin >> pushed[i++];
}
num = tmp;
while (num--)
{
cin >> poped[j++];
}
num = tmp;
int now = 1;
n.push(pushed[0]);
for (int i = 0; i < num; i++)
{
while (poped[i] != n.top() && now < num)
{
n.push(pushed[now++]);
}
if (poped[i] == n.top())n.pop();
else
{
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
}
}