#include <bits/stdc++.h>
using namespace std;
struct hero {
  int p, s;
};
int a[200000];
hero h[200000];
bool cmp(hero a, hero b) {
  if (a.p == b.p) return a.s > b.s;
  return a.p > b.p;
}
int main() {
  int t, n, m;
  for (scanf("%d", &t); t > 0; t--) {
    int max_a = -1, max_p = -1, ans = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      max_a = (max_a < a[i]) ? a[i] : max_a;
    }
    scanf("%d", &m);
    for (int i = 0; i < m; i++) {
      scanf("%d%d", &h[i].p, &h[i].s);
      max_p = (max_p < h[i].p) ? h[i].p : max_p;
    }
    if (max_p < max_a) {
      printf("-1\n");
      continue;
    }
    sort(h, h + m, cmp);
    for (int i = 0, max_s = -1; i < m; i++)
      if (h[i].s > max_s)
        max_s = h[i].s;
      else
        h[i].p = -1;
    sort(h, h + m, cmp);
    for (int q = 0; q < n; ans++) {
      int cnt = 0, max_q = a[q];
      for (int i = 0; i < m && q < n; i++) {
        if (max_q > h[i].p) break;
        while (q < n && cnt < h[i].s && max_q <= h[i].p) {
          q++;
          cnt++;
          max_q = (max_q < a[q]) ? a[q] : max_q;
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
