#include<iostream>
using namespace std;
struct Stack {
int top;
int w[100001] = { 0 };
};
struct Stack s;
int q, n, a[100001], b[100001];
void Init() {
s.top = 0;
}
int Empty() {
if (s.top == 0) return 1;
else return 0;
}
int Full() {
if (s.top >= n) return 1;
else return 0;
}
void push(int x) {
s.w[s.top] = x;
s.top++;
}
int pop() {
s.top--;
int x = s.w[s.top];
return x;
}
int Judge(int a[], int b[]) {
int i = 0, j = 0;
while (i < n ) {
if (a[i] < b[j]) {
if (!Full()) {
push(a[i]);
i++;
}
else {
return 0;
}
}
else if (a[i] == b[j]) {
if (!Full()) {
i++;
j++;
}
else {
return 0;
}
}
else {
if (!Empty()) {
int x = pop();
if (x == b[j]) {
j++;
}
else {
return 0;
}
}
else {
return 0;
}
}
}
while (!Empty()) {
if (j < n) {
int x = pop();
if (x != b[j]) {
return 0;
}
j++;
}
else {
return 0;
}
}
return 1;
}
int main() {
cin >> q;
for (int i = 0; i < q; i++) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int j = 0; j < n; j++) {
cin >> b[j];
}
if (Judge(a, b)) printf("Yes\n");
else printf("No\n");
while (!Empty()) {
pop();
}
}
return 0;
}