#include <bits/stdc++.h>
using namespace std;
const int N = int(2e5) + 99;
int t, n, m;
int a[N], p[N], s[N], bst[N];
int main(void) {
  cin >> t;
  for (int tc = 0; tc < t; tc++) {
    scanf("%d", &n);
    for (int i = 0; i <= n; i++) bst[i] = 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", &p[i], &s[i]);
      bst[s[i]] = max(bst[s[i]], p[i]);
    }
    for (int i = n - 1; i >= 0; i--) bst[i] = max(bst[i], bst[i + 1]);
    int pos = 0, res = 0;
    bool ok = true;
    while (pos < n) {
      res++;
      int npos = pos;
      int mx = 0;
      while (true) {
        mx = max(mx, a[npos]);
        if (mx > bst[npos - pos + 1]) break;
        ++npos;
      }
      if (pos == npos) {
        ok = false;
        break;
      }
      pos = npos;
    }
    if (!ok) res = -1;
    cout << res << endl;
  }
}
