#include<bits/stdc++.h>
#include<chrono>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
auto start = chrono::steady_clock::now();
void init_code(){
fast_io;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int main(){
init_code();
int t;
cin>>t;
while(t--){
int n,k;
cin>>n>>k;
map<int,pair<int,int>> a;
for(int i=0;i<n;i++){
int x;
cin>>x;
if(a.count(x)==0) a[x].first = i;
else a[x].second =i;
}
string ans="yes";
int j=0;
for(int i=0;i<k;i++){
int x,y;
cin>>x>>y;
int d=a[x].second-a[x].first+1;
if( d<0 ||d<y){
ans="no";
break;
}else{
if(j>a[x].first+y){
ans="no";
break;
}
j=a[x].first+y;
a[x].first =j;
}
}
cout<<ans<<endl;
}
return(0);
}
Copy