#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int T;
int n, m;
int a[200005];
int p[200005];
int mx[800005], tag[800005];
inline void clear(int v = 1, int l = 1, int r = n) {
  if (l == r)
    mx[v] = tag[v] = 0;
  else {
    int m = l + r >> 1;
    clear(v << 1, l, m);
    clear(v << 1 | 1, m + 1, r);
    mx[v] = tag[v] = 0;
  }
}
inline void update(int a, int b, int val, int v = 1, int l = 1, int r = n) {
  if (a <= l && r <= b)
    mx[v] = max(mx[v], val), tag[v] = max(tag[v], val);
  else if (r < a || b < l)
    return;
  else {
    mx[v << 1] = max(mx[v << 1], tag[v]);
    mx[v << 1 | 1] = max(mx[v << 1 | 1], tag[v]);
    tag[v << 1] = max(tag[v << 1], tag[v]);
    tag[v << 1 | 1] = max(tag[v << 1 | 1], tag[v]);
    int m = l + r >> 1;
    update(a, b, val, v << 1, l, m);
    update(a, b, val, v << 1 | 1, m + 1, r);
    mx[v] = max(mx[v], max(mx[v << 1], mx[v << 1 | 1]));
  }
}
inline int query(int a, int b, int v = 1, int l = 1, int r = n) {
  if (a <= l && r <= b)
    return mx[v];
  else if (r < a || b < l)
    return 0;
  else {
    mx[v << 1] = max(mx[v << 1], tag[v]);
    mx[v << 1 | 1] = max(mx[v << 1 | 1], tag[v]);
    tag[v << 1] = max(tag[v << 1], tag[v]);
    tag[v << 1 | 1] = max(tag[v << 1 | 1], tag[v]);
    int m = l + r >> 1;
    return max(query(a, b, v << 1, l, m), query(a, b, v << 1 | 1, m + 1, r));
  }
}
int dp[200005];
int main() {
  ios::sync_with_stdio(false);
  cin >> T;
  while (T--) {
    cin >> n;
    for (int i = 1; i <= (n); ++i) cin >> a[i];
    for (int i = 1; i <= (n); ++i) p[i] = 0;
    cin >> m;
    for (int i = 1; i <= (m); ++i) {
      int Pi, Si;
      cin >> Pi >> Si;
      p[Si] = max(p[Si], Pi);
    }
    for (int i = n - 1; i >= 1; --i) p[i] = max(p[i], p[i + 1]);
    bool bad = 0;
    for (int i = 1; i <= (n); ++i)
      if (a[i] > p[1]) {
        cout << -1 << endl;
        bad = 1;
        break;
      }
    if (bad) continue;
    for (int i = 1; i <= (n); ++i) dp[i] = INF;
    dp[0] = 0;
    clear();
    for (int i = 1; i <= n; ++i) {
      update(1, i, a[i]);
      int l = 1, r = i, mid = r;
      if (p[mid] >= query(i - mid + 1, i))
        dp[i] = 1;
      else {
        while (r - l > 1) {
          mid = l + r >> 1;
          if (p[mid] >= query(i - mid + 1, i))
            l = mid;
          else
            r = mid;
        }
        dp[i] = dp[i - l] + 1;
      }
    }
    cout << dp[n] << endl;
  }
  return 0;
}
