#include <bits/stdc++.h>
using namespace std;
const int INF = 1e6 + 9;
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.first < b.first) return true;
  if (a.first == b.first && a.second < b.second)
    return true;
  else
    return false;
}
vector<pair<long long, long long> > h;
long long m, a[200009], sptable[20][200009];
void build() {
  for (int i = 0; i < m; i++) sptable[0][i] = h[i].second;
  for (int i = 1; (1 << i) <= m; i++) {
    for (int j = 0; j + (1 << i) <= m; j++) {
      sptable[i][j] =
          max(sptable[i - 1][j], sptable[i - 1][j + (1 << (i - 1))]);
    }
  }
}
long long query(int a, int b) {
  if (a > b) swap(a, b);
  int lg = __builtin_clz(1) - __builtin_clz(b - a + 1);
  return max(sptable[lg][a], sptable[lg][b - (1 << lg) + 1]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    h.clear();
    int monsters[n + 2];
    int maxfm = -1;
    for (int i = 0; i < n; i++) {
      cin >> monsters[i];
      maxfm = max(monsters[i], maxfm);
    }
    cin >> m;
    int maxft = -1;
    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      h.push_back({a, b});
      maxft = max(a, maxft);
    }
    if (maxft < maxfm) {
      cout << -1 << '\n';
      continue;
    }
    sort(h.begin(), h.end(), comp);
    vector<int> h2;
    for (int i = 0; i < m; i++) {
      h2.push_back(h[i].first);
    }
    build();
    int ans = 0;
    int maxf = -1;
    int contd = 0;
    for (int i = 0; i < n; i++) {
      contd++;
      maxf = max(maxf, monsters[i]);
      int pos = (upper_bound(h2.begin(), h2.end(), maxf - 1) - h2.begin());
      if (pos < m && query(pos, m - 1) >= contd) {
      } else {
        ans++;
        contd = 0;
        maxf = -1;
        i--;
      }
    }
    if (contd > 0) ans++;
    cout << ans << '\n';
  }
  return 0;
}
