#include <bits/stdc++.h>
using namespace std;
inline void minimize(int &x, int y) { x = min(x, y); }
inline void maximize(int &x, int y) { x = max(x, y); }
const int N = 400000 + 1067;
int n, curMonster, top, t, m;
int a[N], p[N], s[N], q[N], it[N * 4], trai[N * 4], phai[N * 4];
int mx[N];
map<int, int> mp;
void build(int x, int l, int r) {
  trai[x] = l;
  phai[x] = r;
  if (l == r) {
    it[x] = a[l];
    return;
  }
  int mid = (l + r) / 2;
  build(x * 2, l, mid);
  build(x * 2 + 1, mid + 1, r);
  it[x] = max(it[x * 2], it[x * 2 + 1]);
}
int query(int x, int l, int r) {
  if (trai[x] > r || phai[x] < l) return 0;
  if (trai[x] >= l && phai[x] <= r) return it[x];
  return max(query(x * 2, l, r), query(x * 2 + 1, l, r));
}
bool check(int x) {
  if (x == 0) return true;
  int mxP = query(1, curMonster + 1, curMonster + x);
  return mx[mxP] >= x;
}
int bs(int l, int r) {
  while (l < r) {
    if (l == r - 1) {
      if (check(r))
        return r;
      else
        return l;
    }
    int mid = (l + r) / 2;
    if (check(mid))
      l = mid;
    else
      r = mid - 1;
  }
  return l;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> t;
  for (int test = 1; test <= t; test++) {
    cin >> n;
    top = 0;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      ++top;
      q[top] = a[i];
    }
    cin >> m;
    for (int i = 1; i <= m; i++) {
      cin >> p[i] >> s[i];
      ++top;
      q[top] = p[i];
    }
    sort(q + 1, q + top + 1);
    int top1 = 0;
    for (int i = 1; i <= top; i++)
      if (q[i] != q[i - 1]) {
        ++top1;
        q[top1] = q[i];
      }
    top = top1;
    for (int i = 1; i <= top; i++) mp[q[i]] = i, mx[i] = 0;
    mx[top + 1] = 0;
    for (int i = 1; i <= n; i++) a[i] = mp[a[i]];
    build(1, 1, n);
    for (int i = 1; i <= m; i++) {
      p[i] = mp[p[i]];
      maximize(mx[p[i]], s[i]);
    }
    for (int i = top - 1; i >= 1; i--) maximize(mx[i], mx[i + 1]);
    curMonster = 0;
    int res = 0;
    while (curMonster < n) {
      int step = bs(0, n - curMonster);
      if (step == 0) {
        res = -1;
        break;
      }
      curMonster += step;
      res++;
    }
    cout << res << endl;
  }
  return 0;
}
