#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5 + 5;
const int M = 1e6;
const long long INF = (long long)(1e18);
const int inf = 1e9;
const long long MOD = 1000000007LL;
int n, m;
int mon[MAX_N], endur[MAX_N];
void solve() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> mon[i];
    endur[i] = 0;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    int p, s;
    cin >> p >> s;
    endur[s] = max(endur[s], p);
  }
  for (int i = n - 1; i >= 1; i--) {
    endur[i] = max(endur[i], endur[i + 1]);
  }
  int ans = 0;
  int cnt = 0;
  while (cnt < n) {
    int x = 1;
    if (mon[cnt + 1] > endur[1]) {
      cout << "-1\n";
      return;
    }
    int maxi = -1;
    while (cnt + x <= n) {
      maxi = max(maxi, mon[cnt + x]);
      if (maxi > endur[x]) break;
      x++;
    }
    ans++;
    cnt += x;
    cnt--;
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
