package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
scanner.Split(bufio.ScanWords)
nextInt := func() int {
scanner.Scan()
res, _ := strconv.Atoi(scanner.Text())
return res
}
nextFloat := func() float64 {
scanner.Scan()
res, _ := strconv.ParseFloat(scanner.Text(), 64)
return res
}
if !scanner.Scan() {
return
}
t, _ := strconv.Atoi(scanner.Text())
for i := 0; i < t; i++ {
n := nextInt()
m := nextInt()
pos := 0
for j := 1; j <= n; j++ {
val := nextInt()
if val != j {
pos = j
}
}
failProb := 1.0
for j := 0; j < m; j++ {
r := nextInt()
p := nextFloat()
if r >= pos {
failProb *= (1.0 - p)
}
}
if pos == 0 {
fmt.Printf("%.6f\n", 1.0)
} else {
fmt.Printf("%.6f\n", 1.0 - failProb)
}
}
}