#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> monster(n);
    for (int i = 0; i < n; ++i) {
      cin >> monster[i];
    }
    int m;
    cin >> m;
    vector<pair<int, int>> hero(m);
    for (int i = 0; i < m; ++i) {
      cin >> hero[i].first >> hero[i].second;
    }
    sort(hero.begin(), hero.end());
    int end = 0;
    for (int i = 0; i < m; ++i) {
      while (end > 0 && hero[end - 1].second <= hero[i].second) --end;
      hero[end] = hero[i];
      ++end;
    }
    hero.resize(end);
    int ans = 0;
    int i = 0;
    int count = 0;
    auto start = hero.begin();
    while (i < n) {
      start = lower_bound(start, hero.end(), pair<int, int>{monster[i], 0});
      if (start == hero.end()) {
        ans = -1;
        count = 0;
        break;
      } else if ((*start).second > count) {
        ++count;
        ++i;
      } else {
        ++ans;
        count = 0;
        start = hero.begin();
      }
    }
    if (count != 0) {
      ++ans;
    }
    cout << ans << "\n";
  }
  return 0;
}
