#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn];
int mx[maxn];
int d[maxn][20];
int cul(int l, int r) {
  int k = log2(r - l + 1);
  return max(d[l][k], d[r - (1 << k) + 1][k]);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) mx[i] = 0;
    for (int i = 1; i <= n; i++) scanf("%d", &d[i][0]);
    for (int j = 1; j < 20; j++)
      for (int i = 1; i + (1 << j) - 1 <= n; i++)
        d[i][j] = max(d[i][j - 1], d[i + (1 << j - 1)][j - 1]);
    int m;
    scanf("%d", &m);
    int p, sx;
    for (int i = 1; i <= m; i++) {
      scanf("%d%d", &p, &sx);
      mx[sx] = max(mx[sx], p);
    }
    for (int i = n - 1; i >= 1; i--) mx[i] = max(mx[i], mx[i + 1]);
    if (mx[1] < cul(1, n)) {
      puts("-1");
      continue;
    }
    int s = 1;
    int ans = 0;
    while (s <= n) {
      int l = s, r = n;
      while (l < r) {
        int mid = (r + l) / 2;
        if (cul(s, mid) > mx[mid - s + 1])
          r = mid;
        else
          l = mid + 1;
      }
      if (cul(s, l) > mx[l - s + 1]) l--;
      ans++;
      s = l + 1;
    }
    printf("%d\n", ans);
  }
}
