#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,prev_x;
int x1,y1;
cin>>x1>>y1;
prev_x=x1;
int d1=a[x1].second-a[x1].first+1;
if(d1<y1){
ans="no";
}
else{
for(int i=1;i<k;i++){
int x,y;
cin>>x>>y;
int d=a[x].second-a[x].first+1;
if(d<y || prev_x>x){
ans="no";
break;
}
prev_x=x;
}
}
cout<<ans<<endl;
}
return(0);
}
Copy