#include <bits/stdc++.h>
using namespace std;
int n, m, a[200007];
int t[200007];
int body() {
  int res = 1;
  for (int i = 0, l = -1, mx = 0; i < n; i++) {
    mx = max(mx, a[i]);
    if (t[i - l] < mx) {
      res++;
      l = i - 1;
      mx = a[i];
    }
    if (t[1] < a[i]) {
      return -1;
    }
  }
  return res;
}
void readf() {
  freopen("inp.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
}
int main() {
  int testc;
  cin >> testc;
  while (testc > 0) {
    testc--;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      t[i + 1] = 0;
    }
    cin >> m;
    for (int i = 0, p, s; i < m; i++) {
      cin >> p >> s;
      t[s] = max(t[s], p);
    }
    for (int i = n - 1; i > 0; i--) t[i] = max(t[i], t[i + 1]);
    cout << body() << endl;
  }
  return 0;
}
