#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define IN freopen("input.txt", "r", stdin)
#define OUT freopen("output.txt", "w", stdout)
typedef vector<int> vi;
typedef pair<int, int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i <= b; i++)
void dfs(string a, string b, int si)
{
}
int main()
{
int tt;
cin >> tt;
while (tt--)
{
int n, k;
cin >> n >> k;
int arr[n];
int frq[100009] = {};
for (int i = 0; i < n; i++)
cin >> arr[i], frq[arr[i]]++;
bool f = 1;
vector <pair <int ,int>>v;
for (int i = 0; i < k; i++)
{
int x, y;
cin >> x >> y;
v.push_back({x,y});
}
for(int i=0;i + 1<k;i++){
if(v[i].first > v[i+1].first ){
f = 0;
break;
}
}
for(int i=0;i<k;i++){
if(v[i].second > frq[v[i].first]){
f = 0;
break;
}
}
if (f)
cout << "YES\n";
else
cout << "NO\n";
}
}
Copy