#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long exgcd(long long a, long long b, long long &x, long long &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long x1, y1;
  long long d = exgcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> vec(n);
  for (int i = 0; i < n; i++) cin >> vec[i];
  long long m;
  cin >> m;
  vector<pair<long long, long long> > vpp;
  vector<long long> mxp(n + 1, 0);
  for (int i = 0; i < m; i++) {
    long long x;
    cin >> x;
    long long y;
    cin >> y;
    vpp.push_back(make_pair(x, y));
    mxp[y] = max(mxp[y], x);
  }
  for (int i = n - 1; i >= 1; i--) {
    mxp[i] = max(mxp[i], mxp[i + 1]);
  }
  long long i = 0, ans = 0;
  bool ok = 1;
  while (i < n) {
    long long cnt = 0;
    long long mx = 0;
    while (cnt < n - i) {
      long long j = i + cnt;
      mx = max(mx, vec[j]);
      if (mxp[cnt + 1] >= mx) {
        ++cnt;
      } else
        break;
    }
    if (cnt == 0) {
      ok = 0;
      break;
    }
    i += cnt;
    ++ans;
  }
  cout << (!ok ? -1 : ans) << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
