#include <bits/stdc++.h>
using namespace std;
int n, m;
int T[8 * 100010];
vector<pair<int, int> > heros;
vector<int> maxStrength;
void update(int k, int l, int r, int u, int v) {
  if (u < l || u > r) return;
  if (l == r) {
    T[k] = v;
    return;
  }
  update(2 * k, l, (l + r) / 2, u, v);
  update(2 * k + 1, (l + r) / 2 + 1, r, u, v);
  T[k] = max(T[2 * k], T[2 * k + 1]);
}
int get(int k, int l, int r, int u, int v) {
  if (v < l || u > r) return 0;
  if (u <= l && r <= v) return T[k];
  return max(get(2 * k, l, (l + r) / 2, u, v),
             get(2 * k + 1, (l + r) / 2 + 1, r, u, v));
}
bool check(int cur, int nxt) {
  int num = nxt - cur + 1;
  int l = -1, r = (int)heros.size(), mid;
  if (num > heros[0].second) return false;
  while (r - l > 1) {
    mid = (l + r) / 2;
    if (heros[mid].second >= num)
      l = mid;
    else
      r = mid;
  }
  return heros[l].first >= get(1, 1, n, cur, nxt);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int nTest;
  cin >> nTest;
  while (nTest--) {
    cin >> n;
    for (int i = 1; i <= 4 * n; i++) T[i] = 0;
    heros.clear();
    for (int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      update(1, 1, n, i, x);
    }
    cin >> m;
    for (int i = 1; i <= m; i++) {
      int a, b;
      cin >> a >> b;
      heros.push_back(pair<int, int>(a, b));
    }
    sort(heros.begin(), heros.end());
    vector<pair<int, int> > temp;
    for (int i = 0; i < heros.size(); i++) {
      while (!temp.empty() && temp.back().second <= heros[i].second)
        temp.pop_back();
      temp.push_back(heros[i]);
    }
    heros = temp;
    int currentDay = 1;
    bool canAns = true;
    int ans = 0;
    while (currentDay <= n) {
      ans++;
      int nx = -1;
      for (int nextDay = currentDay; nextDay <= n + 1; nextDay++) {
        if (nextDay == n + 1) {
          nx = nextDay;
          break;
        }
        if (check(currentDay, nextDay)) continue;
        nx = nextDay;
        break;
      }
      if (nx == -1 || nx == currentDay) {
        canAns = false;
        break;
      }
      currentDay = nx;
    }
    if (!canAns)
      cout << "-1\n";
    else
      cout << ans << "\n";
  }
}
