#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n];
    for (long long i = 0; i < n; i++) cin >> a[i];
    long long m;
    cin >> m;
    vector<pair<long long, long long>> v;
    long long p, s;
    for (long long i = 0; i < m; i++) {
      cin >> p;
      cin >> s;
      v.push_back(make_pair(s, p));
    }
    sort(v.begin(), v.end());
    long long dp[n + 2];
    dp[n + 1] = 0;
    for (long long i = 0; i <= n; i++) dp[i] = 0;
    for (long long i = m - 1; i >= 0; i--) {
      dp[v[i].first] = max(v[i].second, dp[v[i].first]);
    }
    for (long long i = n; i >= 0; i--) {
      dp[i] = max(dp[i + 1], dp[i]);
    }
    long long ans = 0;
    long long cur = 0;
    long long flag = 1;
    for (long long i = 0; cur < n; i++) {
      if (a[cur] > dp[1]) {
        flag = 0;
        break;
      } else {
        ans += 1;
        long long temp = 0;
        long long maxi = a[cur];
        while (maxi <= dp[1 + temp]) {
          temp++;
          maxi = max(maxi, a[cur + temp]);
        }
        cur += temp;
      }
    }
    if (flag == 0) {
      cout << "-1\n";
    } else {
      cout << ans << endl;
    }
  }
}
