#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  long long p1 = 0;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    a[i] = x;
    p1 = max(p1, x);
  }
  long long m;
  cin >> m;
  vector<pair<long long, long long> > b(m);
  long long p2 = 0;
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    b[i].first = x;
    b[i].second = y;
    p2 = max(p2, x);
  }
  if (p2 < p1) {
    cout << -1 << '\n';
    return;
  }
  sort(b.begin(), b.end());
  for (long long i = m - 2; i >= 0; i--) {
    b[i].second = max(b[i].second, b[i + 1].second);
  }
  long long mx = 0;
  long long cnt = -1;
  long long ans = 0;
  long long q = -1;
  for (long long i = 0; i < n; i++) {
    mx = max(mx, a[i]);
    long long j = lower_bound(b.begin(), b.end(), make_pair(mx, q)) - b.begin();
    if (b[j].second < i - cnt) {
      ans++;
      mx = 0;
      i--;
      cnt = i;
    }
  }
  ans++;
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long TESTS = 1;
  cin >> TESTS;
  while (TESTS--) {
    solve();
  }
  return 0;
}
