#include <bits/stdc++.h>
const long long N = 2 * 1e5 + 10;
const long long INF = 1e18;
const long long inf = -1e18;
const long long MOD = 1e9 + 7;
const long long xesh = 31;
using namespace std;
long long n, a[211111], mx[211111], q, w, m, l, ans = 1, sh, i, o;
int main() {
  cin >> o;
  while (o--) {
    cin >> n;
    sh = 0;
    for (i = 1; i <= n; ++i) {
      cin >> a[i];
      mx[i] = 0;
    }
    cin >> m;
    for (i = 1; i <= m; ++i) {
      cin >> q >> w;
      mx[w] = max(q, mx[w]);
    }
    for (i = n - 1; i >= 1; --i) {
      mx[i] = max(mx[i], mx[i + 1]);
    }
    for (i = 1, m = 0, l = 0; i <= n; ++i) {
      m = max(a[i], m);
      if (mx[i - l] < m) {
        l = i - 1;
        ans++;
        m = a[i];
      }
      if (mx[1] < m) {
        sh = 1;
        break;
      }
    }
    if (sh == 1)
      cout << -1 << '\n';
    else
      cout << ans << '\n';
    ans = 1;
  }
}
