#include <bits/stdc++.h>
using namespace std;
long long INF = 1e9;
void solve() {
  long long n, m;
  cin >> n;
  deque<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> m;
  vector<pair<long long, long long>> b(m);
  vector<long long> c(m);
  for (long long i = 0; i < m; i++) {
    cin >> b[i].first >> b[i].second;
    swap(b[i].first, b[i].second);
  }
  sort(b.begin(), b.end());
  for (long long i = 0; i < m; i++) {
    c[i] = b[i].first;
  }
  vector<long long> p(m + 1);
  for (long long i = m - 1; i >= 0; i--) {
    p[i] = max(p[i + 1], b[i].second);
  }
  long long ans = 0;
  while (!a.empty()) {
    long long mx = 0;
    long long cnt = 0;
    for (long long i = 0;; i++) {
      mx = max(a[0], mx);
      cnt++;
      long long id = lower_bound(c.begin(), c.end(), cnt) - c.begin();
      if (!a.empty() && p[id] >= mx)
        a.pop_front();
      else
        break;
    }
    if (cnt == 1) {
      cout << -1 << '\n';
      return;
    }
    ans++;
  }
  cout << ans << '\n';
}
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
