#include <bits/stdc++.h>
using namespace std;
static auto x = []() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  return 0;
}();
const int maxn = 1e6;
struct T {
  int p, s;
} her[maxn], use[maxn];
int dun[maxn], now, maxget;
int cmp(const T& a, const T& b) {
  if (a.p == b.p) return a.s < b.s;
  return a.p < b.p;
}
bool cando(int hero, int nowd) {
  int fail = nowd;
  while (use[hero].p >= dun[fail] && (fail - nowd) < use[hero].s) fail++;
  if ((fail - nowd) == use[hero].s) return true;
  return false;
}
int main() {
  int t;
  cin >> t;
  for (int xh = 1; xh <= t; xh++) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> dun[i];
    int m;
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> her[i].p >> her[i].s;
    }
    sort(her, her + m, cmp);
    use[0] = her[m - 1];
    now = 0;
    for (int i = m - 2; i >= 0; i--) {
      if (her[i].s > use[now].s) {
        use[++now] = her[i];
      }
    }
    int nowd = 1;
    bool p = true;
    for (int i = 1; i <= n; i++)
      if (use[0].p < dun[i]) p = false;
    int ans = 0;
    if (p) {
      while (nowd < n + 1) {
        int l = 0, r = now;
        maxget = 0;
        while (l != r) {
          int mid = (l + r + 1) / 2;
          if (cando(mid, nowd)) {
            l = mid;
          } else {
            int fail = nowd;
            int fai = nowd;
            while (use[mid].p >= dun[fail] && (fail - nowd) < use[mid].s)
              fail++;
            while (use[mid - 1].p >= dun[fai] && (fai - nowd) < use[mid - 1].s)
              fai++;
            if (fail <= fai) {
              r = mid - 1;
            } else
              l = mid;
          }
        }
        int fail = nowd;
        while (use[l].p >= dun[fail] && (fail - nowd) < use[l].s) fail++;
        nowd = fail;
        ans++;
      }
      cout << ans << endl;
    } else
      cout << -1 << endl;
  }
}
