#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int power[maxn], en[maxn], mons[maxn], hero[maxn];
void solve() {
  int n, mxm = -1, mxh = -1, m, ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &mons[i]);
    mxm = max(mxm, mons[i]);
    hero[i] = 0;
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &power[i], &en[i]);
    mxh = max(mxh, power[i]);
    hero[en[i] - 1] = max(hero[en[i] - 1], power[i]);
  }
  if (mxh < mxm) {
    puts("-1");
    return;
  }
  for (int i = n - 2; i >= 0; i--) {
    hero[i] = max(hero[i], hero[i + 1]);
  }
  int day = 0, cur = -1, cons = -1;
  while (day < n) {
    cur = max(cur, mons[day]);
    cons++;
    if (hero[cons] < cur) {
      ans++;
      cons = 0;
      cur = mons[day];
    }
    day++;
  }
  ans++;
  cout << ans << endl;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}
