#include <bits/stdc++.h>
using namespace std;
struct Data {
  int p, s;
  bool operator<(const Data& o) const { return p > o.p || p == o.p && s > o.s; }
};
int a[200000];
Data heros[200000];
int main(int argc, char* argv[]) {
  if (argc == 2 && ((string)argv[1]) == "USE_IO_FILES")
    freopen("in.txt", "r", stdin), freopen("out.txt", "w", stdout);
  int T;
  scanf("%d", &T);
  while (T--) {
    int N;
    scanf("%d", &N);
    for (int i = int(0); i < int(N); i++) scanf("%d", a + i);
    int M;
    scanf("%d", &M);
    for (int i = int(0); i < int(M); i++)
      scanf("%d %d", &heros[i].p, &heros[i].s);
    sort(heros, heros + M);
    int hc = 1;
    for (int i = int(1); i < int(M); i++) {
      if (heros[i].p < heros[hc - 1].p && heros[i].s > heros[hc - 1].s)
        heros[hc++] = heros[i];
    }
    int ans = 0;
    for (int i = int(0); i < int(N); i++) {
      int hhc = 0;
      int bp = 0;
      int j = i;
      while (j < N) {
        bp = max(bp, a[j]);
        if (heros[hhc].p >= bp && heros[hhc].s >= j - i + 1) {
          j++;
        } else if (hhc + 1 < hc && heros[hhc + 1].p >= bp &&
                   heros[hhc + 1].s >= j - i + 1) {
          hhc++;
          j++;
        } else {
          break;
        }
      }
      if (j == i) {
        ans = -1;
        break;
      } else {
        i = j - 1;
        ans++;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
