#include <bits/stdc++.h>
const int MAX = 200000 + 5;
int A[MAX];
int P[MAX];
int S[MAX];
int I[MAX];
bool cmp(int a, int b) { return std::tie(S[a], P[a]) < std::tie(S[b], P[b]); }
bool cmp2(int b, int s) { return s > S[b]; }
int main() {
  std::ios_base::sync_with_stdio(0);
  int t;
  std::cin >> t;
  while (t--) {
    int n, m;
    std::cin >> n;
    for (int i = 0; i < n; ++i) std::cin >> A[i];
    std::cin >> m;
    for (int i = 0; i < m; ++i) std::cin >> P[i] >> S[i];
    for (int i = 0; i <= m; ++i) I[i] = i;
    S[m] = n + 1;
    P[m] = 0;
    std::sort(I, I + m + 1, cmp);
    for (int i = m - 1; i >= 0; --i) P[I[i]] = std::max(P[I[i]], P[I[i + 1]]);
    int days = 0;
    int s = 1;
    int pow = 0;
    for (int i = 0; i < n; ++i) {
      auto it = std::lower_bound(I, I + m + 1, s, cmp2);
      int bestHero = P[*it];
      pow = std::max(pow, A[i]);
      if (bestHero < pow) {
        if (s <= 1) {
          days = -1;
          s = 0;
          break;
        }
        s = 1;
        pow = A[i];
        ++days;
        --i;
      } else {
        ++s;
      }
    }
    if (s > 1) ++days;
    std::cout << days << "\n";
  }
  return 0;
}
