#include <bits/stdc++.h>
using namespace std;
struct tem {
  long long p, s, mx;
};
bool cmp(tem a, tem b) {
  if (a.p > b.p)
    return 1;
  else
    return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    if (n == -1) break;
    long long pn[n];
    for (int i = 0; i <= n - 1; i++) cin >> pn[i];
    long long m;
    cin >> m;
    vector<tem> v;
    for (int i = 0; i <= m - 1; i++) {
      long long a, b;
      cin >> a >> b;
      v.push_back({a, b, 0});
    }
    sort(v.begin(), v.end(), cmp);
    long long mx = 0;
    for (int i = 0; i <= m - 1; i++) {
      mx = max(mx, v[i].s);
      v[i].mx = mx;
    }
    long long ans = 0;
    mx = 0;
    vector<long long> a(m);
    for (int i = 0; i <= m - 1; i++) a[i] = v[i].p;
    long long j = 0, fg = 1;
    mx = 0;
    for (int i = 0; i <= n - 1; i++) {
      j++;
      mx = max(pn[i], mx);
      int ind = (upper_bound(a.begin(), a.end(), mx, greater<long long>()) -
                 a.begin());
      if (ind != 0 && v[ind - 1].mx >= j) {
        if (i == n - 1) {
          ans++;
          break;
        }
      } else if (j > 1) {
        ans++, j = 0, i--, mx = -1;
      } else {
        fg = 0;
        break;
      }
    }
    if (fg == 0) ans = -1;
    cout << ans << endl;
  }
}
