#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int Case;
int n, m, a[N];
struct nd {
  int p, s;
  nd(int _p = 0, int _s = 0) {
    p = _p;
    s = _s;
  }
  friend bool operator<(nd a, nd b) {
    return a.p < b.p || (a.p == b.p && a.s < b.s);
  }
} b[N];
struct ST {
  int tot;
  int ls[N << 1], rs[N << 1], mx[N << 1];
  int build(int l, int r) {
    int x = ++tot;
    if (l == r) {
      mx[x] = a[l];
      return x;
    }
    int mid = l + r >> 1;
    ls[x] = build(l, mid);
    rs[x] = build(mid + 1, r);
    mx[x] = max(mx[ls[x]], mx[rs[x]]);
    return x;
  }
  int getmx(int x, int l, int r, int L, int R) {
    if (L <= l && r <= R) return mx[x];
    int mid = l + r >> 1, ret = 0;
    if (L <= mid) ret = getmx(ls[x], l, mid, L, R);
    if (R > mid) ret = max(ret, getmx(rs[x], mid + 1, r, L, R));
    return ret;
  }
  void rebuild() {
    for (int i = 1; i <= tot; ++i) ls[i] = rs[i] = mx[i] = 0;
    tot = 0;
    build(1, n);
  }
} T;
void Solve() {
  static int mx[N];
  mx[m + 1] = 0;
  for (int i = m; i >= 1; --i) mx[i] = max(mx[i + 1], b[i].s);
  int ans = 0;
  if (*max_element(a + 1, a + n + 1) > b[m].p) {
    cout << -1 << endl;
    return;
  }
  for (int R = 0, l, r; R != n; R = l) {
    l = R + 1, r = n;
    while (l != r) {
      int mid = l + r + 1 >> 1;
      int val = T.getmx(1, 1, n, R + 1, mid);
      int p = lower_bound(b + 1, b + m + 1, nd(val, 0)) - b;
      if (p > m) {
        cout << -1 << endl;
        return;
      }
      if (mx[p] >= mid - R)
        l = mid;
      else
        r = mid - 1;
    }
    ans++;
  }
  cout << ans << endl;
}
int main() {
  cin >> Case;
  while (Case--) {
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    cin >> m;
    for (int i = 1; i <= m; ++i) cin >> b[i].p >> b[i].s;
    sort(b + 1, b + m + 1);
    T.rebuild();
    Solve();
  }
}
