#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
const long long N = 2e5 + 7;
const long long inf = 1e6 + 1;
const long long mod = 998244353;
int t, n, m, a[N];
struct node {
  int def, s;
  bool operator<(const node& a) const { return def < a.def; }
} b[N];
bool cmp(const node& a, int x) { return a.def < x; }
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    cin >> m;
    for (int i = 1; i <= m; i++) cin >> b[i].def >> b[i].s;
    sort(b + 1, b + 1 + m);
    for (int i = m - 1; i >= 1; i--) {
      b[i].s = max(b[i].s, b[i + 1].s);
    }
    bool ok = true;
    int minn = 2 * n, ans = 0, last = 0;
    for (int i = 1; i <= n; i++) {
      int q = lower_bound(b + 1, b + 1 + m, a[i], cmp) - b;
      if (q > m) {
        ok = false;
        break;
      }
      minn = min(minn, b[q].s);
      if (last + minn < i) {
        ans++;
        last = i - 1;
        minn = b[q].s;
      }
    }
    if (ok == false)
      cout << "-1\n";
    else
      cout << ans + 1 << "\n";
  }
  return 0;
}
