#include <bits/stdc++.h>
using namespace std;
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto vv : V) os << vv << ",";
  return os << "]";
}
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << '=' << h << '\n';
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
const int N = 2e5 + 7;
int n, a[N], m, mx[N], days, valid;
pair<int, int> p[N];
int tree[4 * N];
void build(int start, int end, int node) {
  if (start == end) {
    tree[node] = a[start];
    return;
  }
  int mid = (start + end) / 2;
  build(start, mid, 2 * node);
  build(mid + 1, end, 2 * node + 1);
  tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
int query(int start, int end, int node, int l, int r) {
  if (start > r || end < l) return INT_MIN;
  if (l <= start && end <= r) return tree[node];
  int mid = (start + end) / 2;
  int lf = query(start, mid, 2 * node, l, r);
  int rh = query(mid + 1, end, 2 * node + 1, l, r);
  return max(lf, rh);
}
bool check(int i, int j) {
  int maxx = query(0, n - 1, 1, i, j);
  int pos = lower_bound(p, p + m, make_pair(maxx, 0)) - p;
  if (pos == m) {
    valid = 0;
    return false;
  }
  int can_kill = mx[pos];
  return can_kill >= j - i + 1;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    build(0, n - 1, 1);
    cin >> m;
    for (int i = 0; i < m; i++) cin >> p[i].first >> p[i].second;
    sort(p, p + m);
    mx[m - 1] = p[m - 1].second;
    for (int i = m - 2; i >= 0; i--) mx[i] = max(mx[i + 1], p[i].second);
    days = 0, valid = 1;
    for (int i = 0; i < n;) {
      int lo = i, hi = n - 1, nxt = -1;
      while (hi - lo > 1) {
        int mid = (hi + lo) / 2;
        if (check(i, mid))
          lo = mid;
        else
          hi = mid;
      }
      if (check(i, hi))
        nxt = hi + 1;
      else if (check(i, lo))
        nxt = lo + 1;
      else
        valid = 0;
      if (valid == 0) break;
      i = nxt;
      days++;
    }
    if (valid)
      cout << days << '\n';
    else
      cout << -1 << '\n';
  }
  return 0;
}
