#include <bits/stdc++.h>
using namespace std;
vector<int> arr[200005];
vector<int> v;
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;
    for (i = 0; i < n; i++) {
      int in;
      cin >> in;
      mon.push_back(in);
    }
    int m;
    cin >> m;
    vector<pair<int, int> > hero;
    for (i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      hero.push_back({a, b});
    }
    sort(hero.begin(), hero.end(), greater<pair<int, int> >());
    int arr[m + 5];
    arr[0] = hero[0].second;
    for (i = 1; i < m; i++) {
      arr[i] = max(arr[i - 1], hero[i].second);
    }
    int f = 0;
    int ans = 0;
    for (i = 0; i < mon.size();) {
      int l = 0, r = m - 1;
      for (j = i; j < mon.size(); j++) {
        l = 0;
        int val = mon[j];
        int pos = -1;
        while (l <= r) {
          int mid = (l + r) / 2;
          if (hero[mid].first >= val) {
            pos = mid;
            l = mid + 1;
          } else
            r = mid - 1;
        }
        if (pos == -1) {
          f = 1;
          break;
        }
        if (arr[pos] < (j - i + 1)) {
          break;
        }
      }
      if (f) break;
      ans++;
      i = j;
    }
    if (f)
      cout << -1 << "\n";
    else
      cout << ans << "\n";
  }
  return 0;
}
