#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000 + 10;
const long long INFLL = 1000ll * 1000 * 1000 * 1000 * 1000 * 100;
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int &t : a) cin >> t;
  vector<int> log2_(n + 1, 0);
  for (int i = 2; i <= n; ++i) log2_[i] = log2_[i / 2] + 1;
  vector<vector<int> > table(log2_.back() + 1, vector<int>(n, 0));
  for (int i = 0; i < n; ++i) table[0][i] = a[i];
  for (int k = 1; (1 << k) <= n; ++k)
    for (int i = 0; i + (1 << k) <= n; ++i)
      table[k][i] = max(table[k - 1][i], table[k - 1][i + (1 << (k - 1))]);
  auto get = [&](int l, int r) -> int {
    int f = log2_[r - l + 1];
    return max(table[f][l], table[f][r - (1 << f) + 1]);
  };
  int m;
  cin >> m;
  vector<pair<int, int> > h(m);
  for (int i = 0; i < m; ++i) {
    int p, s;
    cin >> p >> s;
    h[i] = {p, s};
  }
  sort(h.begin(), h.end());
  if (*max_element(a.begin(), a.end()) >
      max_element(h.begin(), h.end())->first) {
    cout << "-1\n";
    return;
  }
  for (int i = m - 2; i >= 0; --i)
    h[i].second = max(h[i].second, h[i + 1].second);
  vector<int> dp(n, INF);
  dp[0] = 1;
  for (int i = 1; i < n; ++i) {
    int l = 1, r = i + 2;
    while (r - l > 1) {
      int k = (l + r) / 2;
      int e = get(i - k + 1, i);
      auto it = lower_bound(h.begin(), h.end(), pair<int, int>(e, 0));
      if (it->second < k)
        r = k;
      else
        l = k;
    }
    dp[i] = (i - l >= 0 ? dp[i - l] : 0) + 1;
  }
  cout << dp[n - 1] << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  for (; T; --T) {
    solve();
  }
}
