#include <bits/stdc++.h>
using namespace std;
int a[200005], n, m, t, s[200005];
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 1; i <= n + 1; i++) s[i] = 0;
    cin >> m;
    for (int i = 0; i < m; i++) {
      int l, r;
      cin >> l >> r;
      s[r] = max(s[r], l);
    }
    for (int i = n - 1; i >= 1; i--) {
      s[i] = max(s[i], s[i + 1]);
    }
    int day = 0, now = 0;
    while (now < n) {
      int maxn = -1, k = 0;
      while (now + k < n && max(maxn, a[now + k]) <= s[k + 1]) {
        maxn = max(maxn, a[now + k]);
        k++;
      }
      if (k == 0) {
        day = -1;
        break;
      } else {
        day++;
        now += k;
      }
    }
    cout << day << endl;
  }
  return 0;
}
