#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
long long mon[N + 5];
long long en[N + 5];
vector<pair<long long, long long> > v;
vector<long long> dn;
int32_t main() {
  ios_base::sync_with_stdio(0);
  long long t;
  cin >> t;
  while (t--) {
    dn.clear();
    v.clear();
    long long n, m, x, y;
    cin >> n;
    long long lx = 0;
    for (long long i = 1; i <= n; i++) {
      cin >> mon[i];
      lx = max(lx, mon[i]);
    }
    cin >> m;
    long long rx = 0;
    for (long long i = 1; i <= m; i++) {
      cin >> x >> y;
      v.push_back({x, y});
      rx = max(rx, x);
    }
    if (lx > rx) {
      cout << -1 << "\n";
      continue;
    }
    sort(v.begin(), v.end());
    for (long long i = 0; i < m; i++) {
      dn.push_back(v[i].first);
    }
    long long ans = 1, mx = 0;
    for (long long i = m - 1; i >= 0; i--) {
      mx = max(mx, v[i].second);
      en[i] = mx;
    }
    long long k = 0, p = 0, c = 0;
    for (long long i = 1; i <= n; i++) {
      p = max(p, mon[i]);
      c++;
      long long r = upper_bound(dn.begin(), dn.end(), p - 1) - dn.begin();
      if (v[r].first >= p && en[r] >= c) {
        continue;
      } else {
        ++ans;
        p = mon[i];
        c = 1;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
