#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
T pow(T a, T b, long long int m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m;
    b /= 2;
    a = ((a % m) * (a % m)) % m;
  }
  return ans % m;
}
template <typename T>
void tracev(vector<T> &a) {
  for (auto &i : a) {
    cout << i << ' ';
  }
  cout << '\n';
}
template <typename T>
void tracevv(vector<T> &a) {
  for (auto &i : a) {
    tracev(i);
  }
}
template <typename T>
void tracevp(vector<T> &a) {
  for (auto &i : a) {
    cout << "i.ff"
         << ": " << i.first << " | "
         << "i.ss"
         << ": " << i.second << "\n";
    ;
  }
  cout << '\n';
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    vector<long long int> a(n);
    for (long long int i = 0; i < n; i++) cin >> a[i];
    long long int m;
    cin >> m;
    vector<pair<long long int, long long int> > b(n, {0, 0});
    for (long long int i = 0; i < m; i++) {
      long long int u, v;
      cin >> u >> v;
      if (u > b[v - 1].first) {
        b[v - 1] = {u, v - 1};
      }
    }
    for (long long int i = n - 2; i >= 0; i--) {
      if (b[i + 1].first >= b[i].first) {
        b[i] = b[i + 1];
      }
    }
    long long int ans = 1;
    long long int st = 0;
    long long int i = 0;
    long long int gm = 0;
    while (i < n) {
      gm = max(gm, a[i]);
      if ((i - st == 0) && b[(i - st)].first < gm) {
        ans = -1;
        break;
      }
      if (b[(i - st)].first < gm || b[(i - st)].second < (i - st)) {
        ans++;
        st = i;
        gm = 0;
        i--;
      }
      i++;
    }
    cout << ans << '\n';
  }
  return 0;
}
