#include <bits/stdc++.h>
using namespace std;
int q;
int n, m, t[800000], val[200300], days = 0;
vector<pair<int, int> > a(200300);
bool comp(pair<int, int> d, pair<int, int> d1) {
  if (d.first != d1.first) {
    return (d.first < d1.first);
  }
  return (d.second < d1.second);
}
void build(int ver, int l, int r) {
  if (l == r) {
    t[ver] = a[l].second;
    return;
  }
  int mid = l + (r - l) / 2;
  build(ver * 2, l, mid);
  build(ver * 2 + 1, mid + 1, r);
  t[ver] = max(t[ver * 2], t[ver * 2 + 1]);
}
int getMax(int ver, int l, int r, int nl, int nr) {
  if (l > nr || r < nl) {
    return -1;
  }
  if (l >= nl && r <= nr) {
    return t[ver];
  }
  int mid = l + (r - l) / 2;
  return max(getMax(ver * 2, l, mid, nl, nr),
             getMax(ver * 2 + 1, mid + 1, r, nl, nr));
}
int _findPos(int ch) {
  int l = 0, r = m;
  if (ch > a[r].first) {
    return -1;
  }
  while (r - l > 1) {
    int mid = l + (r - l) / 2;
    if (a[mid].first >= ch) {
      r = mid;
    } else {
      l = mid;
    }
  }
  return r;
}
void solve() {
  days = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> val[i];
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a[i].first >> a[i].second;
  }
  sort(a.begin() + 1, a.begin() + m + 1, comp);
  build(1, 1, m);
  int curL = 1;
  int curR = 1;
  int curMax = 0;
  int border = 1;
  while (curL != n + 1) {
    if (val[curR] > curMax) {
      curMax = val[curR];
      border = _findPos(curMax);
    }
    if (border == -1) {
      cout << -1 << endl;
      return;
    }
    int t = getMax(1, 1, m, border, m);
    if (t < curR - curL + 1) {
      days++;
      curL = curR;
      curR = curL;
      curMax = 0;
      border = 1;
    } else {
      curR++;
      if (curR == n + 1) {
        days++;
        break;
      }
    }
  }
  cout << days << endl;
}
int main() {
  cin >> q;
  while (q != 0) {
    solve();
    q--;
  }
}
