#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    vector<int> a(n, 0);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    int m;
    scanf("%d", &m);
    vector<pair<int, int> > h(m, {0, 0});
    for (int i = 0; i < m; i++) scanf("%d%d", &h[i].first, &h[i].second);
    sort(h.begin(), h.end());
    vector<int> suf(m, 0);
    suf[m - 1] = h[m - 1].second;
    for (int i = m - 2; i >= 0; i--) suf[i] = max(suf[i + 1], h[i].second);
    int ans = 0;
    int bad = 0;
    for (int i = 0; i < n;) {
      int j = i;
      int mx = 0;
      while (j < n) {
        mx = max(mx, a[j]);
        int p = lower_bound(h.begin(), h.end(), make_pair(mx, -1)) - h.begin();
        if (p < m && suf[p] >= j - i + 1)
          j++;
        else
          break;
      }
      if (j <= i) {
        bad = 1;
        break;
      }
      ans++;
      i = j;
    }
    if (bad)
      printf("-1\n");
    else
      printf("%d\n", ans);
  }
  return 0;
}
