> File Name: 8.cpp
> Author: jiangyuzhu
> Mail: 834138558@qq.com
> Created Time: 2016/8/11 10:20:15
************************************************************************/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<algorithm>
using namespace std;
typedef pair<int, int>p;
const int maxn = 1e3 + 5;
int a[maxn], b[maxn];
int ans[maxn];
struct OP{
int l, r;
}op[maxn];
int main (void)
{
int T;scanf("%d", &T);
while(T--){
queue<int>q[maxn];
int n, m;scanf("%d%d", &n, &m);
for(int i = 0; i < n; i++){
scanf("%d", &a[i]);
}
for(int i = 0; i < n; i++){
scanf("%d", &b[i]);
q[b[i]].push(i);
}
bool flag = true;
for(int i = 0; i < n; i++){
if(q[a[i]].empty()){
flag = false;
break;
}
ans[i] = q[a[i]].front();
q[a[i]].pop();
}
for(int i = 0; i < m; i++){
scanf("%d%d", &op[i].l, &op[i].r);
}
if(!flag){
puts("No");
continue;
}
for(int i = 0; i < m; i++){
sort(ans + op[i].l - 1, ans + op[i].r);
}
for(int i = 0; i < n; i++){
if(ans[i] != i){
flag = false;
break;
}
}
if(!flag) puts("No");
else puts("Yes");
}
return 0;
}