#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int N, M, A[maxn];
pair<int, int> hero[maxn];
int ma[maxn];
int R[maxn];
int finds(int need) {
  int l = lower_bound(hero + 1, hero + 1 + M, make_pair(need, -1)) - hero;
  return ma[l];
}
void solve(void) {
  cin >> N;
  int Max = 0;
  for (int i = 1; i <= N; ++i) cin >> A[i], Max = max(Max, A[i]);
  cin >> M;
  for (int i = 1; i <= M; ++i) cin >> hero[i].first >> hero[i].second;
  sort(hero + 1, hero + 1 + M);
  ma[M + 1] = -1e9 - 5;
  for (int i = M; i >= 1; --i) ma[i] = max(hero[i].second, ma[i + 1]);
  if (Max > hero[M].first) {
    cout << "-1\n";
    return;
  }
  int j = 1;
  int res = 0;
  while (j <= N) {
    ++res;
    int cj = j;
    int maA = 0;
    while (cj <= N) {
      maA = max(maA, A[cj]);
      if (j + finds(maA) <= cj) break;
      ++cj;
    }
    j = cj;
  }
  cout << res << '\n';
}
signed main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) solve();
}
