#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, m, a[maxn], suf[maxn], b[maxn], p[maxn], s[maxn];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) b[i] = -1;
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    scanf("%d", &m);
    for (int i = 1; i <= m; i++)
      scanf("%d %d", &p[i], &s[i]), b[s[i]] = max(b[s[i]], p[i]);
    suf[n + 1] = -1;
    for (int i = n; i >= 1; i--) suf[i] = max(suf[i + 1], b[i]);
    int pos = 1, ans = 0;
    while (pos <= n) {
      int cur = pos;
      int maxx = a[pos];
      while (cur <= n && suf[cur - pos + 1] >= maxx) {
        cur++;
        maxx = max(maxx, a[cur]);
      }
      if (cur == pos) {
        ans = -1;
        break;
      }
      ans++;
      pos = cur;
    }
    printf("%d\n", ans);
  }
}
