#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int t, n, a[200002], m, suf[200002];
pair<int, int> v[200002];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    cin >> m;
    for (int i = 1; i <= m; i++) {
      cin >> v[i].first >> v[i].second;
    }
    sort(v + 1, v + m + 1);
    suf[m + 1] = 0;
    for (int i = m; i >= 1; i--) suf[i] = max(suf[i + 1], v[i].second);
    int i = 1;
    int sol = 0;
    while (i <= n) {
      int j = i;
      int mx = 0;
      while (j <= n) {
        mx = max(mx, a[j]);
        int st = 1, dr = m, ans = -1;
        while (st <= dr) {
          int mij = (st + dr) / 2;
          if (v[mij].first >= mx) {
            dr = mij - 1;
            ans = mij;
          } else
            st = mij + 1;
        }
        if (ans == -1 || suf[ans] < (j - i + 1)) break;
        j++;
      }
      if (i == j) {
        sol = -1;
        break;
      }
      i = j;
      sol++;
    }
    cout << sol << "\n";
  }
  return 0;
}
