#include <bits/stdc++.h>
using namespace std;
namespace _ {
bool rEOF = 1;
inline char nc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && rEOF &&
                 (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? (rEOF = 0, EOF)
             : *p1++;
}
template <class _T>
inline bool read(_T &num) {
  char c = nc(), f = 1;
  num = 0;
  while (c < '0' || c > '9') c == '-' && (f = -1), c = nc();
  while (c >= '0' && c <= '9') num = num * 10 + c - '0', c = nc();
  return (bool)(num *= f);
}
inline bool need(char &c) {
  return c >= 'a' && c <= 'z' || c >= '0' && c <= '9' || c >= 'A' && c <= 'Z';
}
inline bool read_str(char *a) {
  while ((*a = nc()) && need(*a) && rEOF) ++a;
  *a = '\0';
  return rEOF;
}
}  // namespace _
using namespace _;
void file(bool opt) {
  if (opt && fopen("in.txt", "r")) {
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
  }
}
int a[200000 + 5];
int p[200000 + 5], px, py;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    cin >> m;
    int R = 0;
    for (int i = 1; i <= m; i++)
      cin >> px >> py, p[py] = max(p[py], px), R = max(R, py);
    for (int i = R - 1; i >= 1; i--) p[i] = max(p[i], p[i + 1]);
    int ans = 0;
    for (int x = 1; x <= n;) {
      if (a[x] > p[1]) {
        ans = -1;
        break;
      }
      int d = 0;
      int mx = a[x];
      while (d <= R - 1 && mx <= p[d + 1]) d++, mx = max(mx, a[x + d]);
      ans++;
      x = x + d;
    }
    cout << ans << endl;
    for (int i = 1; i <= R; i++) p[i] = 0;
  }
  return 0;
}
