#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> Pii;
long long qpow(long long a, long long b, long long m) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % m;
    a = a * a % m, b >>= 1;
  }
  return ans;
}
long long qpow(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a;
    a = a * a, b >>= 1;
  }
  return ans;
}
long long qmul(long long a, long long b, long long m) {
  long long res = 0;
  while (b > 0) {
    if (b & 1) res = (res + a) % m;
    a = (a + a) % m;
    b >>= 1;
  }
  return res;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long inv(long long t, long long p) {
  return t == 1 ? 1 : (p - p / t) * inv(p % t, p) % p;
}
long long exgcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long r = exgcd(b, a % b, y, x);
  y -= (a / b) * x;
  return r;
}
long long inv1(long long a, long long p) {
  long long d, x, y;
  d = exgcd(a, p, x, y);
  return d == 1 ? (x % p + p) % p : -1;
}
template <typename T, typename B>
T Add(T a, B b, long long m) {
  return a + b >= m ? (a + b) % m : a + b;
}
template <typename T, typename B>
T Sub(T a, B b, long long m) {
  return a - b < 0 ? (a - b + m) % m : a - b;
}
template <typename T>
void sf(T &a) {
  cin >> a;
}
template <typename T, typename B>
void sf(T &a, B &b) {
  cin >> a >> b;
}
template <typename T, typename B, typename C>
void sf(T &a, B &b, C &c) {
  cin >> a >> b >> c;
}
template <typename T>
void pf(const T &a, char c = '\n') {
  cout << a << c;
}
template <typename T, typename B>
void pf(const T &a, const B &b, char c = '\n') {
  cout << a << " " << b << c;
}
template <typename T>
void pff(const T &a, int l = 7, char c = '\n') {
  cout << setprecision(l + 1) << a << c;
}
template <typename T>
inline void read(T &x) {
  x = 0;
  static int p;
  p = 1;
  static char c;
  c = getchar();
  while (!isdigit(c)) {
    if (c == '-') p = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c - 48);
    c = getchar();
  }
  x *= p;
}
const bool IOS = false;
const double PI = acos(-1);
const double eps = 1e-8;
const long long linf = 0x3f3f3f3f3f3f3f3f;
const long long INV2 = 500000004;
const long long mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 200000 + 20;
int a[maxn];
int b[maxn];
int lg2[maxn];
struct ST {
  int st[maxn][30];
  int pos[maxn][30];
  void init(int *a, int n) {
    for (int i = 1; i <= n; ++i) st[i][0] = a[i], pos[i][0] = i;
    for (int j = 1; j <= lg2[n]; ++j)
      for (int i = 1; i + (1 << j) - 1 <= n; ++i) {
        st[i][j] = max(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
        pos[i][j] = (st[i][j - 1] < st[i + (1 << (j - 1))][j - 1])
                        ? pos[i][j - 1]
                        : pos[i + (1 << (j - 1))][j - 1];
      }
  }
  int RMQ(int l, int r) {
    int k = lg2[r - l + 1];
    return max(st[l][k], st[r - (1 << k) + 1][k]);
  }
} st1, st2;
bool check(int k, int id, int n) {
  int mx = st1.RMQ(id - k + 1, id);
  int l = mx, r = inf;
  int mx1 = st2.RMQ(k, n);
  if (mx1 >= mx)
    return 1;
  else
    return 0;
}
void Main();
int main() {
  if (IOS) std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  Main();
  0;
  return 0;
}
void Main() {
  int t;
  scanf("%d", &t);
  lg2[0] = -1;
  for (int i = 1; i < maxn; i++) lg2[i] = lg2[i >> 1] + 1;
  while (t--) {
    int n, m, mx = -inf;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
      scanf("%d", &a[i]), mx = max(a[i], mx), b[i] = 0;
    st1.init(a, n);
    scanf("%d", &m);
    int x, y, mx1 = -inf;
    for (int i = 1; i <= m; ++i)
      scanf("%d%d", &x, &y), b[y] = max(b[y], x), mx1 = max(x, mx1);
    st2.init(b, n + 1);
    if (mx > mx1)
      printf("-1\n");
    else {
      int ans = 0;
      int i = n;
      while (i >= 1) {
        int l = 1, r = i + 1, mid;
        while (l <= r) {
          mid = (l + r) >> 1;
          if (check(mid, i, n)) {
            l = mid + 1;
          } else
            r = mid - 1;
        }
        i -= r;
        ans++;
      }
      printf("%d\n", ans);
    }
  }
}
