#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
bool cmp(pair<int64_t, int64_t> a, pair<int64_t, int64_t> b) {
  if (a.first > b.first)
    return true;
  else if (a.first < b.first)
    return false;
  else if (a.second > b.second)
    return false;
  else
    return true;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int64_t t;
  cin >> t;
  while (t--) {
    int64_t n;
    cin >> n;
    int64_t a[n];
    int64_t maxm = 0;
    for (int64_t i = 0; i < n; i++) {
      cin >> a[i];
      maxm = max(maxm, a[i]);
    }
    int64_t m;
    cin >> m;
    pair<int64_t, int64_t> h[m];
    int64_t x, y;
    int64_t maxh = 0;
    for (int64_t i = 0; i < m; i++) {
      cin >> x >> y;
      h[i] = {x, y};
      maxh = max(maxh, x);
    }
    int64_t ans = 0;
    if (maxm > maxh) {
      cout << -1 << "\n";
      continue;
    }
    int64_t j = 0;
    bool f = false;
    sort(h, h + m, cmp);
    while (!f) {
      if (j == n) break;
      int64_t currmax = 0;
      int64_t maxs = 0;
      for (int64_t i = 0; i < h[0].second; i++) {
        if (j + i >= n) {
          f = true;
          break;
        }
        if (a[j + i] > h[0].first) {
          break;
        }
        maxs = max(maxs, a[j + i]);
        currmax = i + 1;
      }
      int64_t l = 0, r = m - 1;
      if (f) {
        ans++;
        j = j + currmax;
        break;
      }
      while (l <= r) {
        int64_t mid = (l + r) / 2;
        if (h[mid].first < maxs) {
          r = mid - 1;
        } else if (h[mid].second <= currmax) {
          l = mid + 1;
        } else {
          for (int64_t i = currmax; i < h[mid].second; i++) {
            if (j + i >= n) {
              f = true;
              break;
            }
            if (a[j + i] > h[mid].first) {
              break;
            }
            maxs = max(maxs, a[j + i]);
            currmax = i + 1;
          }
          l = mid + 1;
        }
        if (f) break;
      }
      ans++;
      j = j + currmax;
      if (f) break;
    }
    cout << ans << "\n";
  }
  return 0;
}
