package main
import (
"bufio"
"os"
"strconv"
)
func main() {
var scanner = bufio.NewScanner(os.Stdin)
scanner.Split(bufio.ScanWords)
var writer = bufio.NewWriter(os.Stdout)
defer writer.Flush()
scanInt := func() int {
scanner.Scan()
val, _ := strconv.Atoi(scanner.Text())
return val
}
if scanner.Scan() {
t, _ := strconv.Atoi(scanner.Text())
for i := 0; i < t; i++ {
n := scanInt()
a := make([]int, n)
for j := 0; j < n; j++ {
a[j] = scanInt()
}
m := scanInt()
bestP := make([]int, n+1)
for j := 0; j < m; j++ {
p := scanInt()
s := scanInt()
if s > n {
s = n
}
if p > bestP[s] {
bestP[s] = p
}
}
for j := n - 1; j >= 1; j-- {
if bestP[j+1] > bestP[j] {
bestP[j] = bestP[j+1]
}
}
days := 0
curr := 0
possible := true
for curr < n {
days++
step := 0
mx := 0
for curr+step < n {
if a[curr+step] > mx {
mx = a[curr+step]
}
if mx > bestP[step+1] {
break
}
step++
}
if step == 0 {
possible = false
break
}
curr += step
}
if possible {
writer.WriteString(strconv.Itoa(days))
writer.WriteByte('\n')
} else {
writer.WriteString("-1\n")
}
}
}
}