#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int t, n, m, a[200010];
pair<int, int> S[200010];
int SF[200010];
int c[200010 << 2];
void build(int p, int l, int r) {
  if (l == r) {
    c[p] = a[l];
    return;
  }
  int mid = ((l) + ((r) - (l)) / 2);
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  c[p] = max(c[p << 1], c[p << 1 | 1]);
}
int get(int p, int a, int b, int l, int r) {
  if (a <= l && r <= b) {
    return c[p];
  }
  int mid = ((l) + ((r) - (l)) / 2);
  int ans = 0;
  if (a <= mid) ans = max(ans, get(p << 1, a, b, l, mid));
  if (b >= mid + 1) ans = max(ans, get(p << 1 | 1, a, b, mid + 1, r));
  return ans;
}
bool check(int p, int mid) {
  int tmax = get(1, p + 1, mid, 1, n);
  int pos = lower_bound(SF + 1, SF + m + 1, tmax) - SF;
  if (S[pos].second >= mid - p) {
    return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> t;
  for (int q = 1; q <= t; ++q) {
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    build(1, 1, n);
    cin >> m;
    for (int i = 1; i <= m; ++i) {
      cin >> S[i].first >> S[i].second;
    }
    sort(S + 1, S + m + 1);
    if (get(1, 1, n, 1, n) > S[m].first) {
      cout << -1 << endl;
      continue;
    }
    for (int i = 1; i <= m; ++i) SF[i] = S[i].first;
    for (int i = m - 1; i >= 1; --i)
      S[i].second = max(S[i].second, S[i + 1].second);
    int p = 0, ans = 0;
    while (p < n) {
      int l = p + 1, r = n;
      while (l < r) {
        int mid = ((l) + ((r) - (l)) / 2);
        if (check(p, mid))
          l = mid + 1;
        else
          r = mid;
      }
      if (l > n || !check(p, l)) l--;
      p = l;
      ans++;
    }
    cout << ans << endl;
  }
  return 0;
}
