You play a computer game. In this game, you lead a party of $m$ heroes, and you have to clear a dungeon with $n$ monsters. Each monster is characterized by its power $a_i$. Each hero is characterized by his power $p_i$ and endurance $s_i$.

The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.

When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated $k$ monsters, the hero fights with the monster $k + 1$). When the hero fights the monster, there are two possible outcomes:

  if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends;  otherwise, the monster is defeated. 

After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the $i$-th hero cannot defeat more than $s_i$ monsters during each day), or if all monsters are defeated — otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.

Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 10^5$) — the number of test cases. Then the test cases follow.

The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of monsters in the dungeon.

The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the power of the $i$-th monster.

The third line contains one integer $m$ ($1 \le m \le 2 \cdot 10^5$) — the number of heroes in your party.

Then $m$ lines follow, each describing a hero. Each line contains two integers $p_i$ and $s_i$ ($1 \le p_i \le 10^9$, $1 \le s_i \le n$) — the power and the endurance of the $i$-th hero.

It is guaranteed that the sum of $n + m$ over all test cases does not exceed $2 \cdot 10^5$.


-----Output-----

For each test case print one integer — the minimum number of days you have to spend to defeat all of the monsters (or $-1$ if it is impossible).


-----Example-----
Input
2
6
2 3 11 14 1 8
2
3 2
100 1
5
3 5 100 2 3
2
30 5
90 1

Output
5
-1

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = "# -*- coding: utf-8 -*-\n\nimport sys\nfrom bisect import bisect_left\n\ndef input(): return sys.stdin.readline().strip()\ndef list2d(a, b, c): return [[c] * b for i in range(a)]\ndef list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]\ndef list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]\ndef ceil(x, y=1): return int(-(-x // y))\ndef INT(): return int(input())\ndef MAP(): return list(map(int, input().split()))\ndef LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]\ndef Yes(): print('Yes')\ndef No(): print('No')\ndef YES(): print('YES')\ndef NO(): print('NO')\nsys.setrecursionlimit(10 ** 9)\nINF = 10 ** 18\nMOD = 10 ** 9 + 7\n\nclass SegTree:\n\n    def __init__(self, n, func, intv, A=[]):\n\n        self.n = n\n        self.func = func\n        self.intv = intv\n        n2 = 1\n        while n2 < n:\n            n2 <<= 1\n        self.n2 = n2\n        self.tree = [self.intv] * (n2 << 1)\n        if A:\n            for i in range(n):\n                self.tree[n2+i] = A[i]\n            for i in range(n2-1, -1, -1):\n                self.tree[i] = self.func(self.tree[i*2], self.tree[i*2+1])\n\n    def update(self, i, x):\n\n        i += self.n2\n        self.tree[i] = x\n        while i > 0:\n            i >>= 1\n            self.tree[i] = self.func(self.tree[i*2], self.tree[i*2+1])\n\n    def query(self, a, b):\n\n        l = a + self.n2\n        r = b + self.n2\n        s = self.intv\n        while l < r:\n            if r & 1:\n                r -= 1\n                s = self.func(s, self.tree[r])\n            if l & 1:\n                s = self.func(s, self.tree[l])\n                l += 1\n            l >>= 1\n            r >>= 1\n        return s\n\n    def get(self, i):\n        return self.tree[i+self.n2]\n\n    def all(self):\n        return self.tree[1]\n\ndef bisearch_max(mn, mx, func):\n\n    ok = mn\n    ng = mx\n    while ok+1 < ng:\n        mid = (ok+ng) // 2\n        if func(mid):\n            ok = mid\n        else:\n            ng = mid\n    return ok\n\ndef check(m):\n    mx = st.query(cur, m)\n    idx = bisect_left(P, mx)\n    if idx == M:\n        return False\n    _, s = PS[idx]\n    scnt = m - cur\n    return s >= scnt\n\nans = []\nfor _ in range(INT()):\n    N = INT()\n    A = LIST()\n    M = INT()\n    PS = []\n    for i in range(M):\n        p, s = MAP()\n        PS.append((p, s))\n\n    PS.sort()\n    for i in range(M-1, 0, -1):\n        if PS[i][1] > PS[i-1][1]:\n            PS[i-1] = (PS[i-1][0], PS[i][1])\n    P, _ = list(zip(*PS))\n    \n    st = SegTree(N, max, 0, A)\n    cur = day = 0\n    while cur < N:\n        res = bisearch_max(cur, N+1, check)\n        if res == cur:\n            ans.append(str(-1))\n            break\n        cur = res\n        day += 1\n    else:\n        ans.append(str(day))\n\nprint('\\n'.join(ans))\n"
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 19815