#include <bits/stdc++.h>
using namespace std;
class SparseTable {
 public:
  vector<vector<int>> st;
  vector<int> log;
  SparseTable(vector<int> candidate) {
    int N = candidate.size();
    log = vector<int>(N + 1);
    log[1] = 0;
    for (int i = 2; i <= N; ++i) {
      log[i] = log[i >> 1] + 1;
    }
    int K = log[N] + 1;
    st = vector<vector<int>>(N, vector<int>(K));
    for (int i = 0; i < N; ++i) {
      st[i][0] = candidate[i];
    }
    for (int j = 1; j <= K; j++) {
      for (int i = 0; i + (1 << j) <= N; i++) {
        st[i][j] = max(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
      }
    }
  }
  int query(int L, int R) {
    int j = log[R - L + 1];
    return max(st[L][j], st[R - (1 << j) + 1][j]);
  }
};
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; ++i) cin >> arr[i];
    int m;
    cin >> m;
    vector<pair<int, int>> heroes;
    for (int i = 0; i < m; ++i) {
      int p, s;
      cin >> p >> s;
      heroes.emplace_back(s, p);
    }
    sort(heroes.begin(), heroes.end());
    vector<int> powers(m);
    vector<int> endurance(m);
    for (int i = 0; i < m; ++i) {
      endurance[i] = heroes[i].first;
      powers[i] = heroes[i].second;
    }
    if (*max_element(powers.begin(), powers.end()) <
        *max_element(arr.begin(), arr.end())) {
      cout << -1 << endl;
      continue;
    }
    SparseTable table(powers);
    int cover = 0;
    int res = 1;
    int end = 0;
    int i = 0;
    while (i < n) {
      ++end;
      int idx = lower_bound(endurance.begin(), endurance.end(), end) -
                endurance.begin();
      cover = max(cover, arr[i]);
      if (idx < m && table.query(idx, m - 1) >= cover) {
        ++i;
      } else {
        ++res;
        cover = 0;
        end = 0;
      }
    }
    cout << res << endl;
  }
}
