#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int monsters[MAXN];
pair<int, int> heroes[MAXN];
bool Bsearch(int l, int r, int p, int s) {
  while (l <= r) {
    int m = (l + r) >> 1;
    if (heroes[m].first < p)
      l = m + 1;
    else if (m > 0 && heroes[m - 1].first >= p)
      r = m - 1;
    else {
      if (heroes[m].second >= s) return true;
      return false;
    }
  }
  return false;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", &monsters[i]);
    int m;
    scanf("%d", &m);
    for (int i = 0; i < m; ++i)
      scanf("%d%d", &heroes[i].first, &heroes[i].second);
    sort(heroes, heroes + m);
    for (int i = m - 1; i > 0; --i)
      heroes[i - 1].second = max(heroes[i - 1].second, heroes[i].second);
    int ans = 1;
    int p = monsters[0];
    int s = 1;
    for (int i = 0; i < n; ++i) {
      p = max(p, monsters[i]);
      if (Bsearch(0, m - 1, p, s))
        ++s;
      else {
        if (s == 1) {
          ans = -1;
          break;
        }
        ++ans;
        p = monsters[i];
        s = 1;
        --i;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
