#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int t, n, m, i, j, k, sum = 0;
  cin >> n;
  vector<long long int> a(n);
  long long int maxa = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    maxa = max(maxa, a[i]);
  }
  cin >> m;
  vector<pair<long long int, long long int>> b(m);
  long long int maxb = 0;
  for (i = 0; i < m; i++) {
    cin >> b[i].first >> b[i].second;
    maxb = max(maxb, b[i].first);
  }
  if (maxa > maxb) {
    cout << -1 << '\n';
    return;
  }
  sort(b.begin(), b.end());
  long long int mmax = b[m - 1].second;
  vector<pair<long long int, long long int>> c;
  c.push_back({b[m - 1].second, b[m - 1].first});
  for (i = m - 2; i >= 0; i--) {
    long long int j = c.size() - 1;
    if (b[i].second > c[j].first) {
      c.push_back({b[i].second, b[i].first});
    }
  }
  sort(c.begin(), c.end());
  vector<long long int> aa, bb;
  for (i = 0; i < c.size(); i++) {
    aa.push_back(c[i].first);
    bb.push_back(c[i].second);
  }
  mmax = 0;
  j = 0;
  long long int ans = 1;
  for (i = 0; i < n; i++) {
    mmax = max(mmax, a[i]);
    long long int temp = i - j + 1;
    auto z = lower_bound(aa.begin(), aa.end(), temp);
    if (z == aa.end()) {
      mmax = 0;
      j = i;
      ans++;
      i--;
    } else if (bb[z - aa.begin()] < mmax) {
      mmax = 0;
      j = i;
      ans++;
      i--;
    }
  }
  cout << ans << '\n';
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int q;
  cin >> q;
  while (q--) {
    solve();
  }
  return 0;
}
