#include <bits/stdc++.h>
using namespace std;
int n, m, mon[200005], x, y, ans, tmp, len;
map<int, int> mp;
vector<pair<int, int> > vec;
set<pair<int, int> > st;
set<pair<int, int> >::iterator up;
bool check(int l, int r, int mx) {
  len = r - l + 1;
  up = st.upper_bound({len, -2e9});
  if (up == st.end()) return 0;
  if ((*up).second < mx) return 0;
  return 1;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &mon[i]);
    }
    scanf("%d", &m);
    for (int i = 1; i <= m; i++) {
      scanf("%d%d", &x, &y);
      mp[y] = max(mp[y], x);
    }
    for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++)
      vec.push_back({it->first, it->second});
    sort(vec.begin(), vec.end());
    st.insert({vec[vec.size() - 1].first, vec[vec.size() - 1].second});
    for (int i = vec.size() - 2; i > -1; i--) {
      vec[i].second = max(vec[i].second, vec[i + 1].second);
      st.insert({vec[i].first, vec[i].second});
    }
    int l = 1, r = 1, mx = 0;
    ans = 1;
    while (r <= n) {
      mx = max(mx, mon[r]);
      if (check(l, r, mx))
        r++;
      else {
        if (l == r) {
          ans = -1;
          break;
        } else {
          ans++;
          l = r;
          mx = mon[l];
        }
      }
    }
    printf("%d\n", ans);
    mp.clear();
    ans = 0;
    vec.clear(), st.clear();
  }
  return 0;
}
