#include <bits/stdc++.h>
using namespace std;
template <class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
  return os << "{" << p.first << ", " << p.second << "}";
}
template <class t>
ostream& operator<<(ostream& os, const vector<t>& v) {
  os << "{";
  for (int i = (int)(0); i < (int)(v.size()); i++) {
    if (i) os << ", ";
    os << v[i];
  }
  return os << "}";
}
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
void solve() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = (int)(0); i < (int)(N); i++) {
    cin >> A[i];
  }
  int M;
  cin >> M;
  vector<long long> P(M);
  vector<int> S(M);
  vector<long long> B(N + 1);
  for (int i = (int)(0); i < (int)(M); i++) {
    cin >> P[i] >> S[i];
    B[S[i]] = max(P[i], B[S[i]]);
  }
  for (int i = (int)(N - 1); i >= (int)(1); i--) B[i] = max(B[i], B[i + 1]);
  int pos = 0;
  int ans = 0;
  bool ok = true;
  while (pos < N) {
    ++ans;
    int npos = pos;
    long long mx = 0;
    while (npos < N) {
      mx = max(mx, A[npos]);
      if (mx > B[npos - pos + 1]) break;
      ++npos;
    }
    if (pos == npos) {
      ok = false;
      break;
    }
    pos = npos;
  }
  if (!ok) ans = -1;
  cout << ans << endl;
}
int main() {
  int T;
  cin >> T;
  for (int t = (int)(0); t < (int)(T); t++) solve();
  return 0;
}
