#include <bits/stdc++.h>
using namespace std;
const long long INF =
    sizeof(long long) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const long long MOD = (long long)(1e9) + 7;
using pii = pair<long long, long long>;
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T>
void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  for (long long i = (0); i < (v.size()); i++)
    for (long long j = (0); j < (v[i].size()); j++) {
      if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
        cerr << "INF";
      } else
        cerr << v[i][j];
      cerr << (j == v[i].size() - 1 ? '\n' : ' ');
    }
  cerr << endl;
}
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U>
bool chmax(T &a, U b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename Monoid>
struct SegmentTree {
  using F = function<Monoid(Monoid, Monoid)>;
  long long sz;
  vector<Monoid> seg;
  const F f;
  const Monoid e;
  SegmentTree(long long n, const F f, const Monoid &e) : f(f), e(e) {
    sz = 1;
    while (sz < n) sz <<= 1;
    seg.assign(2 * sz, e);
  }
  void set(long long k, const Monoid &x) { seg[k + sz] = x; }
  void build() {
    for (long long k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
  void update(long long k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while (k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
  Monoid query(long long a, long long b) {
    Monoid L = e, R = e;
    for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if (a & 1) L = f(L, seg[a++]);
      if (b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }
  const Monoid &operator[](const long long &k) const { return seg[k + sz]; }
  Monoid &operator[](const long long &k) { return seg[k + sz]; }
};
signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  long long T;
  cin >> T;
  for (long long loop = ((0)); loop < ((T)); loop++) {
    long long N;
    cin >> N;
    vector<long long> a(N);
    for (long long i = (0); i < (N); i++) {
      cin >> a[i];
    }
    long long M;
    cin >> M;
    vector<long long> p(N + 2);
    for (long long loop = ((0)); loop < ((M)); loop++) {
      long long a, b;
      cin >> a >> b;
      chmax(p[b], a);
    }
    for (long long i = (N + 1) - 1; i >= (1); i--) {
      chmax(p[i], p[i + 1]);
    }
    long long i = 0;
    long long ans = 0;
    while (i < N) {
      long long x = 0;
      long long j;
      for (j = 0; i + j < N; j++) {
        chmax(x, a[i + j]);
        if (p[j + 1] < x) {
          break;
        }
      }
      if (j == 0) {
        ans = -1;
        break;
      }
      ans++;
      i += j;
    }
    cout << ans << endl;
  }
  return 0;
}
