#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > a, a2;
vector<int> b;
int main() {
  int t;
  cin >> t;
  for (int q = 0; q < t; q++) {
    int m;
    cin >> m;
    b.resize(m);
    for (int i = 0; i < m; i++) {
      cin >> b[i];
    }
    int n;
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i].first;
      cin >> a[i].second;
    }
    sort(a.begin(), a.end());
    a2.clear();
    for (int i = 0; i < n; i++) {
      while (a2.size() > 0 && a2.back().second <= a[i].second) {
        a2.pop_back();
      }
      a2.push_back(a[i]);
    }
    a = a2;
    n = a.size();
    int l = 0;
    int mx = 0;
    int ans = 1;
    for (int i = 0; i < m; i++) {
      mx = max(mx, b[i]);
      int j = lower_bound(a.begin(), a.end(), make_pair(mx, 0)) - a.begin();
      if (j == n) {
        ans = -1;
        break;
      }
      if (a[j].second < i - l + 1) {
        ans++;
        l = i;
        mx = b[i];
      }
    }
    cout << ans << endl;
  }
  return 0;
}
