#include <bits/stdc++.h>
using namespace std;
int m, h;
vector<int> monsters;
map<int, int> heroes;
int fight(int start) {
  int dist = 1;
  int m = monsters[start];
  if (heroes[dist] < m) return -1;
  while (heroes[dist] >= m) {
    dist++;
    start++;
    m = max(m, monsters[start]);
  }
  return start;
}
void solve_test_case() {
  monsters.clear();
  heroes.clear();
  cin >> m;
  for (int i = 0; i < m; i++) {
    int v;
    cin >> v;
    monsters.push_back(v);
  }
  monsters.push_back(2000000000);
  cin >> h;
  for (int i = 0; i < h; i++) {
    int p, e;
    cin >> p >> e;
    if (heroes.find(e) == heroes.end()) {
      heroes[e] = p;
    } else {
      heroes[e] = max(p, heroes[e]);
    }
  }
  for (int e = m; e > 0; e--) {
    heroes[e] = max(heroes[e + 1], heroes[e]);
  }
  int days = 0;
  int last_pos = 0;
  while (last_pos < m) {
    last_pos = fight(last_pos);
    if (last_pos == -1) {
      cout << -1 << endl;
      return;
    }
    days++;
  }
  cout << days << endl;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) solve_test_case();
  return 0;
}
