#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int N=2e5+9;
int t,n,k,a[N];
vector<pair<int,int>>v;
map<int,int>cnt;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>t;
while(t--){
v.clear();
cin>>n>>k;
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<k;i++){
int x,y;
cin>>x>>y;
v.push_back({x,y});
}
bool all=true;
int i=n-1;
for(int j=k-1;j>=0;j--){
int x=v[j].first;
int y=v[j].second;
cnt.clear();
bool ok=false;
while(i>=0){
cnt[a[i]]++;
i--;
if(cnt[x]==y){
ok=true;
break;
}
}
if(!ok)all=false;
}
cout<<(all?"yes":"no")<<'\n';
}
}
Copy