#include <bits/stdc++.h>
using namespace std;
long long a[201000];
long long vis[201000];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), vis[i] = 0;
    int m;
    scanf("%d", &m);
    for (int i = 1; i <= m; i++) {
      long long x, y;
      scanf("%lld%lld", &x, &y);
      vis[y] = max(vis[y], x);
    }
    for (int i = n - 1; i >= 1; i--) {
      if (vis[i] < vis[i + 1]) vis[i] = vis[i + 1];
    }
    long long ans = 1;
    long long num = 0, co = 0;
    int vis1 = 0;
    for (int i = 1; i <= n; i++) {
      num++;
      if (vis[num] >= max(co, a[i])) {
        co = max(co, a[i]);
      } else {
        ans++;
        num--;
        if (vis[1] < a[i]) vis1 = 1;
        num = 1, co = a[i];
      }
    }
    if (vis1)
      printf("-1\n");
    else
      printf("%lld\n", ans);
  }
}
