#include <bits/stdc++.h>
using namespace std;
long long fpow(long long a, int b, int mod) {
  long long res = 1;
  for (; b > 0; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res % mod;
}
const int mod = 1e9 + 7;
const int N = 2e5 + 100;
inline int read() {
  static char buf[1000000], *p1 = buf, *p2 = buf;
  register int x = false;
  register char ch =
      p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
          ? EOF
          : *p1++;
  ;
  register bool sgn = false;
  while (ch != '-' && (ch < '0' || ch > '9'))
    ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
             ? EOF
             : *p1++;
  ;
  if (ch == '-')
    sgn = true,
    ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
             ? EOF
             : *p1++;
  ;
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch ^ 48),
    ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
             ? EOF
             : *p1++;
  ;
  return sgn ? -x : x;
}
int mon[N];
int d[N];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &mon[i]);
    scanf("%d", &m);
    for (int i = 1; i <= m; i++) {
      int a, b;
      scanf("%d%d", &a, &b);
      d[b] = max(a, d[b]);
    }
    for (int i = n; i >= 0; i--) d[i] = max(d[i + 1], d[i]);
    int ans = 0;
    for (int i = 1; i <= n;) {
      if (mon[i] > d[1]) {
        cout << "-1" << endl;
        goto brk;
      }
      int j = 0;
      int MX = 0;
      for (; j <= n; j++) {
        MX = max(MX, mon[i + j]);
        if (d[j + 1] < MX) break;
      }
      ans++;
      i += j;
    }
    cout << ans << endl;
  brk:;
    for (int i = 0; i <= n; i++) d[i] = 0;
  }
  return 0;
}
