#include <bits/stdc++.h>
using namespace std;
int main() {
  int i = 0, j = 0, cs = 0, in;
  unsigned long long T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    vector<int> mon;
    int m1 = 0;
    for (i = 0; i < n; i++) {
      int in;
      cin >> in;
      m1 = max(m1, in);
      mon.push_back(in);
    }
    vector<pair<int, int> > hero;
    int m;
    cin >> m;
    int m2 = 0;
    int arr[n + 5];
    memset(arr, 0, sizeof(arr));
    for (i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      m2 = max(m2, a);
      hero.push_back({a, b});
      arr[b] = max(arr[b], a);
    }
    if (m1 > m2) {
      cout << -1 << "\n";
      continue;
    }
    for (i = n - 1; i > 0; i--) {
      arr[i] = max(arr[i], arr[i + 1]);
    }
    int ans = 0;
    for (i = 0; i < mon.size();) {
      int val = mon[i];
      for (j = i; j < mon.size(); j++) {
        val = max(mon[j], val);
        if (arr[j - i + 1] >= val)
          ;
        else
          break;
      }
      ans++;
      i = j;
    }
    cout << ans << "\n";
  }
  return 0;
}
