#include <bits/stdc++.h>
using namespace std;
int i, i0, n, m, T, a[200005];
pair<int, int> b[200005];
int tree[800005];
void b_tree(int l, int r, int p) {
  if (l == r)
    tree[p] = a[l];
  else {
    b_tree(l, ((l + r) / 2), p * 2), b_tree(((l + r) / 2) + 1, r, p * 2 + 1);
    tree[p] = max(tree[p * 2], tree[p * 2 + 1]);
  }
}
int q_tree(int l, int r, int p, int a, int b) {
  if (l == a && r == b)
    return tree[p];
  else {
    if (b <= ((l + r) / 2))
      return q_tree(l, ((l + r) / 2), p * 2, a, b);
    else if (a >= ((l + r) / 2) + 1)
      return q_tree(((l + r) / 2) + 1, r, p * 2 + 1, a, b);
    else
      return max(q_tree(l, ((l + r) / 2), p * 2, a, ((l + r) / 2)),
                 q_tree(((l + r) / 2) + 1, r, p * 2 + 1, ((l + r) / 2) + 1, b));
  }
}
int cal(int x) {
  int l = 0, r = m;
  while (l < r) {
    int mid = (l + r) / 2;
    if (b[mid].first < x)
      l = mid + 1;
    else
      r = mid;
  }
  return b[l].second;
}
bool chk(int l, int x) {
  int mx = q_tree(1, n, 1, l, x);
  int len = cal(mx);
  return x - l + 1 <= len;
}
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    scanf("%d", &m);
    for (int i = 1; i <= m; i++) scanf("%d %d", &b[i].first, &b[i].second);
    sort(b + 1, b + 1 + m);
    for (int i = 2; i <= m; i++)
      if (b[i].first == b[i - 1].first)
        b[i].second = max(b[i].second, b[i - 1].second);
    for (int i = m - 1; i; i--) b[i].second = max(b[i].second, b[i + 1].second);
    b_tree(1, n, 1);
    if (q_tree(1, n, 1, 1, n) > b[m].first) {
      printf("-1\n");
      continue;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      int l = i, r = n;
      while (l < r) {
        int mid = (l + r + 1) / 2;
        if (chk(i, mid))
          l = mid;
        else
          r = mid - 1;
      }
      ans++;
      i = r;
    }
    printf("%d\n", ans);
  }
  return 0;
}
