#include <bits/stdc++.h>
using namespace std;
int sz[1000005], sz1[1000005], sz2[1000005];
struct f {
  int x, y;
};
f szm[1000005];
bool cmp(f a, f b) {
  if (a.x == b.x) return a.y < b.y;
  return a.x < b.x;
}
int main() {
  int t, n, m;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &sz[i]);
    }
    scanf("%d", &m);
    for (int i = 1; i <= m; i++) {
      scanf("%d%d", &szm[i].x, &szm[i].y);
    }
    sort(szm + 1, szm + m + 1, cmp);
    int temp = 0;
    for (int i = m; i >= 1; i--) {
      sz1[i] = szm[i].x;
      temp = max(szm[i].y, temp);
      sz2[i] = temp;
    }
    int ans = 0, flag = 0;
    for (int i = 1; i <= n; i++) {
      int maxn = sz[i], s = 0;
      while (1) {
        maxn = max(maxn, sz[i]);
        int q = lower_bound(sz1 + 1, sz1 + m + 1, maxn) - sz1;
        if (q == m + 1) {
          printf("-1\n");
          flag = 1;
          break;
        }
        s++;
        i++;
        if (sz2[q] < s) {
          i -= 2;
          break;
        }
        if (sz2[q] == s || i == n + 1) {
          i--;
          break;
        }
      }
      ans++;
      if (flag) break;
    }
    if (!flag) {
      printf("%d\n", ans);
    }
  }
  return 0;
}
