#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
bool isperfect(long long n) {
  long long y = sqrt(n);
  if (n % y == 0 && y * y == n) return true;
  return false;
}
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.first == b.first) return a.second > b.second;
  return a.first < b.first;
}
long long powi(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) ans = (ans * a);
    b = b >> 1;
    a = (a * a);
  }
  return ans;
}
bool isprime(long long n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
bool prime[10000000];
void seive() {
  prime[1] = true;
  for (int i = 2; i * i < 10000000; i++) {
    if (prime[i]) continue;
    for (int j = i * i; j < 10000000; j += i) {
      prime[j] = true;
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long int> mon(n);
    for (int i = 0; i < n; i++) cin >> mon[i];
    long long m;
    cin >> m;
    pair<long long, long long> p[m];
    long long k = *max_element(mon.begin(), mon.end());
    vector<long long int> v(m);
    long long maxi = INT_MIN;
    for (int i = 0; i < m; i++) {
      cin >> p[i].first;
      cin >> p[i].second;
      maxi = max(maxi, p[i].first);
      v[i] = p[i].second;
    }
    if (maxi < k) {
      cout << "-1" << endl;
      continue;
    }
    sort(p, p + m);
    long long prev = -1;
    long long cnt = 0;
    for (int i = m - 2; i >= 0; i--) {
      p[i].second = max(p[i].second, p[i + 1].second);
    }
    for (int i = 0; i < m; i++) {
      v[i] = p[i].second;
    }
    int flag = 1;
    maxi = 0;
    long long endu = 1;
    for (int i = 0; i < n;) {
      maxi = max(maxi, mon[i]);
      long long lb =
          lower_bound(p, p + m,
                      make_pair(maxi, numeric_limits<long long>::min())) -
          p;
      if (lb > m - 1) lb = m - 1;
      if (p[lb].second >= endu) {
        endu++;
        i++;
      } else {
        cnt++;
        maxi = mon[i];
        endu = 1;
      }
    }
    cout << cnt + 1 << endl;
  }
}
