#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int P[N], S[N], A[N];
int bst[N];
int T, n, m;
int main() {
  cin >> T;
  while (T--) {
    cin >> n;
    memset(bst, 0, (10 + n) * sizeof(int));
    for (int i = 0; i < n; i++) {
      cin >> A[i];
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> P[i] >> S[i];
      bst[S[i]] = max(bst[S[i]], P[i]);
    }
    for (int i = n - 1; i >= 0; i--) {
      bst[i] = max(bst[i + 1], bst[i]);
    }
    int now = 0;
    int ans = 0;
    int ok = 1;
    while (now < n) {
      int cnt = 0;
      int maxx = 0;
      maxx = max(maxx, A[now + cnt]);
      while (bst[cnt + 1] >= maxx) {
        cnt++;
        if (now + cnt == n) {
          break;
        }
        maxx = max(maxx, A[now + cnt]);
      }
      if (cnt == 0) {
        ok = -1;
        break;
      }
      now += cnt;
      ans++;
    }
    if (ok == -1) {
      cout << "-1" << endl;
    } else {
      cout << ans << endl;
    }
  }
}
