#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> a(n + 1);
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
  a[n] = (1LL << 50);
  long long int m;
  cin >> m;
  vector<pair<long long int, long long int>> v(m);
  for (int i = 0; i < m; i++) scanf("%lld %lld", &v[i].first, &v[i].second);
  sort(v.rbegin(), v.rend());
  vector<long long int> mx(n + 1, 0);
  long long int pos = 0;
  for (long long int i = 0; i < m; i++) {
    for (long long int j = pos; j < v[i].second; j++) {
      chmax(mx[j], v[i].first);
    }
    chmax(pos, v[i].second);
  }
  for (int i = 0; i < n; i++)
    if (0)
      cout << "i"
           << "=" << i << " "
           << "mx[i]"
           << "=" << mx[i] << endl;
  ;
  long long int cnt = 0;
  long long int now = 0;
  while (now < n) {
    if (0)
      cout << "now"
           << "=" << now << " " << endl;
    ;
    long long int s = now;
    long long int prevMaxP = a[now];
    while (now < n && mx[now - s] >= prevMaxP && mx[now - s] >= prevMaxP) {
      now++;
      chmax(prevMaxP, a[now]);
    }
    if (now == s) {
      cout << -1 << endl;
      return;
    }
    cnt++;
  }
  printf("%lld\n", cnt);
}
int main() {
  long long int q;
  cin >> q;
  for (int i = 0; i < q; i++) solve();
}
