#include <bits/stdc++.h>
using namespace std;
using u1 = bool;
using u8 = char;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
template <class T>
using V = vector<T>;
template <class T>
using Q = queue<T>;
template <class T>
using S = set<T>;
template <class K, class V>
using M = map<K, V>;
template <class K, class V>
using UM = unordered_map<K, V>;
int main() {
  i32 Q;
  cin >> Q;
  for (i32 q = 0; q < Q; ++q) {
    i32 m;
    cin >> m;
    V<i32> monsters(m);
    for (i32& c : monsters) cin >> c;
    i32 h;
    cin >> h;
    V<i32> heroes((u32)monsters.size() + 4, 0);
    for (i32 i = 0; i < h; ++i) {
      i32 power, stamina;
      cin >> power >> stamina;
      heroes[stamina] = max(heroes[stamina], power);
    }
    for (i32 i = heroes.size() - 2; ~i; --i) {
      heroes[i] = max(heroes[i], heroes[i + 1]);
    }
    i32 days = 0;
    i32 p = 0;
    bool failed = false;
    while (p < monsters.size()) {
      if (monsters[p] > heroes[1]) {
        failed = true;
        break;
      }
      i32 j = 0;
      i32 hardest_monster = monsters[p];
      while (p + j < monsters.size() && hardest_monster <= heroes[j + 1]) {
        j++;
        hardest_monster = max(hardest_monster, monsters[p + j]);
      }
      p += j;
      days++;
    }
    if (failed) {
      cout << -1 << endl;
    } else {
      cout << days << endl;
    }
  }
}
namespace {
auto fast_io = [] {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  return 0;
}();
}
