#include <bits/stdc++.h>
using namespace std;
long long solve() {
  int n, m;
  cin >> n;
  int a[n];
  for (auto &aa : a) cin >> aa;
  cin >> m;
  vector<int> endPwr(n + 2, -1);
  for (int i = 0; i < m; i++) {
    int p, e;
    cin >> p >> e;
    endPwr[e] = max(endPwr[e], p);
  }
  for (int i = n - 1; i >= 0; i--) {
    endPwr[i] = max(endPwr[i + 1], endPwr[i]);
  }
  int ans = 0;
  for (int i = 0; i < n;) {
    ans++;
    int maxi = 0, k = i;
    for (int j = i; j < n; ++j, i = j) {
      maxi = max(maxi, a[j]);
      if (endPwr[j - k + 1] < maxi) {
        if (j == k)
          return cout << "-1\n", 0;
        else
          break;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int _;
  for (cin >> _; _; _--) solve();
  return 0;
}
