#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int maxn = 200009;
const int inf = 1000000000;
int a[maxn];
pair<int, int> op[maxn];
int dat[3 * maxn], datb[3 * maxn];
int query(int *pq, int a, int b, int k, int l, int r) {
  if (a >= b) return 0;
  if (a >= r || b <= l) return 0;
  if (a <= l && b >= r) return pq[k];
  int mid = (l + r) / 2;
  int p = query(pq, a, b, 2 * k + 1, l, mid);
  int q = query(pq, a, b, 2 * k + 2, mid, r);
  return max(p, q);
}
void update(int *pq, int a, int k, int l, int r, int p) {
  if (a < l || a >= r) return;
  if (l == r - 1 && a == l) {
    pq[k] = p;
    return;
  }
  int mid = (l + r) / 2;
  update(pq, a, 2 * k + 1, l, mid, p);
  update(pq, a, 2 * k + 2, mid, r, p);
  pq[k] = max(pq[2 * k + 1], pq[2 * k + 2]);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    scanf("%d", &n);
    int tmp = 0;
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    scanf("%d", &m);
    for (int i = 0; i < m; ++i)
      scanf("%d%d", &op[i].second, &op[i].first), tmp = max(tmp, op[i].first);
    sort(op, op + m);
    for (int i = 0; i < 3 * m; ++i) dat[i] = 0;
    for (int i = 0; i < 3 * n; ++i) datb[i] = 0;
    for (int i = 0; i < m; ++i) update(dat, i, 0, 0, m, op[i].second);
    for (int i = 0; i < n; ++i) update(datb, i, 0, 0, n, a[i]);
    int pos = 0, fg = 1, cnt = 0;
    while (pos < n) {
      int l = 0, r = min(n - pos, tmp) + 1;
      while (l < r - 1) {
        int mid = (r + l) / 2;
        int hj = query(datb, pos, pos + mid, 0, 0, n);
        int io = lower_bound(op, op + m, make_pair(mid, 0)) - op;
        int gh = query(dat, io, m, 0, 0, m);
        if (gh >= hj)
          l = mid;
        else
          r = mid;
      }
      if (l == 0) {
        fg = 0;
        break;
      }
      ++cnt;
      pos += l;
    }
    if (!fg)
      puts("-1");
    else
      printf("%d\n", cnt);
  }
  return 0;
}
