#include <bits/stdc++.h>
using namespace std;
int a[200005];
pair<int, int> h[200005];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    int m;
    cin >> m;
    for (int i = 0; i < m; i++) cin >> h[i].first >> h[i].second;
    sort(h, h + m);
    vector<pair<int, int>> v;
    for (int i = 0; i < m; i++) {
      while (!v.empty() && v.back().second < h[i].second) v.pop_back();
      v.push_back(h[i]);
    }
    int i = 0, ans = 0;
    while (i < n) {
      int j = i, p = a[i];
      while (j < n) {
        auto it = lower_bound(v.begin(), v.end(), make_pair(p, 0));
        if (it == v.end() || it->second < j - i + 1) break;
        p = max(a[++j], p);
      }
      if (j == i) {
        cout << -1 << endl;
        break;
      }
      i = j;
      ans++;
    }
    if (i == n) cout << ans << endl;
  }
}
