#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;
}
frq[v[i].first] -= v[i].second;
if (i == k - 1 && v[i].first == v[i - 1].first && frq[v[i].first > 0])
f = 0;
}
int sum = 0;
for (int i = 0; i < k; i++)
{
sum += v[i].second;
}
if (sum > n)
f = 0;
if (f)
cout << "yes\n";
else
cout << "no\n";
}
}
Copy