Ron is a happy owner of a permutation a of length n.

A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).

<image>

Ron's permutation is subjected to m experiments of the following type: (r_i, p_i). This means that elements in range [1, r_i] (in other words, the prefix of length r_i) have to be sorted in ascending order with the probability of p_i. All experiments are performed in the same order in which they are specified in the input data.

As an example, let's take a look at a permutation [4, 2, 1, 5, 3] and an experiment (3, 0.6). After such an experiment with the probability of 60\% the permutation will assume the form [1, 2, 4, 5, 3] and with a 40\% probability it will remain unchanged.

You have to determine the probability of the permutation becoming completely sorted in ascending order after m experiments.

Input

Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 100).

The first line of each test case contains two integers n and m (1 ≤ n, m ≤ 10^5) — the length of the permutation and the number of experiments, respectively.

The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ n) — contents of the permutation.

The following m lines of each test case each contain an integer r_i and a real number p_i (1 ≤ r_i ≤ n, 0 ≤ p_i ≤ 1) — the length of the prefix and the probability of it being sorted. All probabilities are given with at most 6 decimal places.

It is guaranteed that the sum of n and the sum of m does not exceed 10^5 (∑ n, ∑ m ≤ 10^5).

Output

For each test case, print a single number — the probability that after all experiments the permutation becomes sorted in ascending order. Your answer will be considered correct if its absolute or relative error does not exceed 10^{-6}.

Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} ≤ 10^{-6}.

Example

Input


4
4 3
4 3 2 1
1 0.3
3 1
4 0.6
5 3
4 2 1 3 5
3 0.8
4 0.6
5 0.3
6 5
1 3 2 4 5 6
4 0.9
5 0.3
2 0.4
6 0.7
3 0.5
4 2
1 2 3 4
2 0.5
4 0.1


Output


0.600000
0.720000
0.989500
1.000000

Note

Explanation of the first test case: It can be demonstrated that whether the final permutation is sorted or not depends solely on sorting being performed in the (4, 0.6) experiment.

Difficulty: MEDIUM
Tags: Dynamic programming

Mathematics

Probability
Skill types: Dynamic programming

Starter code:

Solutions:
import os, sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		a = list(map(int, input().split()))
		j = n - 1
		while j != -1 and a[j] == j + 1:
			j -= 1
		if j == -1:
			for _ in range(m):
				x = input()
			print(1)
			continue
		ans = 0
		fac = 1
		for _ in range(m):
			(r, p) = map(float, input().split())
			r = int(r)
			if r >= j + 1:
				ans += fac * p
				fac *= 1 - p
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().strip(' ').split(' '))
	arr = list(map(int, input().strip(' ').split(' ')))
	temp = n
	while temp and arr[temp - 1] == temp:
		temp -= 1
	prob = 1
	for i in range(m):
		(r, p) = map(float, input().strip(' ').split(' '))
		if r >= temp:
			prob *= 1 - p
	if temp == 0:
		print(1)
	else:
		print(1 - prob)


t = int(input())
for _t in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	sorteda = a.copy()
	sorteda.sort()
	sortedlen = n
	for i in range(n - 1, -1, -1):
		if a[i] == sorteda[i]:
			sortedlen -= 1
		else:
			break
	mul = 1
	ans = 0
	for i in range(m):
		(r, p) = input().split()
		r = int(r)
		p = float(p)
		if r >= sortedlen:
			ans += mul * p
			mul = mul * (1 - p)
	print(1) if sortedlen == 0 else print('%.7f' % ans)


from itertools import accumulate

def mul(iterable):
	result = 1
	for x in iterable:
		result *= x
	return result

def read_ints():
	return map(int, input().split())
(t_n,) = read_ints()
for i_t in range(t_n):
	(n, m) = read_ints()
	a_seq = tuple(read_ints())
	operations = [None] * m
	for i_operation in range(m):
		(r, p) = input().split()
		r = int(r) - 1
		p = float(p)
		operations[i_operation] = (r, p)
	prefix_maxs = tuple(accumulate(a_seq, max))
	min_r = n - 1
	while min_r != -1 and a_seq[min_r] == prefix_maxs[min_r]:
		min_r -= 1
	if min_r == -1:
		result = 1.0
	else:
		chances = [p for (r, p) in operations if r >= min_r]
		result = 1.0 - mul((1.0 - p for p in chances))
	print(result)


import sys
input = iter(sys.stdin.read().splitlines()).__next__
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	a_sort = sorted(a)
	need = n
	while a_sort[need - 1] == a[need - 1]:
		need -= 1
		if need == 0:
			break
	prob_fail = 1
	for op in range(m):
		(r, p) = map(float, input().split())
		if r >= need:
			prob_fail *= 1 - p
	print(1 - prob_fail if need > 0 else 1)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().strip().split()))[:n]
	p = 1
	i = n - 1
	while i >= 0:
		if arr[i] != i + 1:
			break
		i -= 1
	ans = 0
	i += 1
	for z in range(k):
		(a, b) = map(float, input().split())
		if a >= i:
			ans += p * b
			p = p * (1 - b)
	if i == 0:
		ans = 1.0
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = (int(x) for x in input().split())
	initial_permutation = tuple((int(x) for x in input().split()))
	last_unsorted_i = n
	for in_p in range(n, 0, -1):
		if initial_permutation[in_p - 1] != in_p:
			last_unsorted_i = in_p
			break
	else:
		for m_i in range(m):
			input()
		print(1)
		continue
	fail_prob = 1
	for m_i in range(m):
		(r_i, p_i) = input().split()
		r_i = int(r_i)
		p_i = float(p_i)
		if r_i >= last_unsorted_i:
			fail_prob *= 1 - p_i
	print(1 - fail_prob)


from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	(n, m) = tuple((int(x) for x in stdin.readline().split()))
	data = tuple((int(x) for x in stdin.readline().split()))
	exp = []
	for _ in range(m):
		exp.append(stdin.readline().split())
	for last in range(n - 1, -1, -1):
		if last != data[last] - 1:
			break
	else:
		print(1.0)
		continue
	ans = 1
	for e in exp:
		if int(e[0]) > last:
			ans *= 1 - float(e[1])
	print(1 - ans)


t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	res = n
	f = 0
	ans = 1
	for i in range(n - 1, -1, -1):
		if a[i] == i + 1:
			res = res - 1
		else:
			break
	for i in range(0, m):
		(r, p) = input().split()
		if int(r) >= res:
			f = 1
			ans = ans * (1 - float(p))
	if res == 0:
		print('1')
	elif f == 1:
		print(1 - ans)
	else:
		print('0')


t = int(input().strip())

def handle(exp, perm, n):
	last_index = n - 1
	if n == 1:
		return 1.0
	elif perm[last_index] == n:
		last_index -= 1
		if last_index == 0:
			return 1.0
		while perm[last_index] == last_index + 1:
			last_index -= 1
			if last_index == 0:
				return 1.0
	not_prob = 1.0
	for k in exp.keys():
		if k >= last_index + 1:
			for i in exp[k]:
				not_prob *= 1.0 - i
	return 1.0 - not_prob
for i in range(t):
	line = input().strip().split()
	(n, m) = (int(line[0]), int(line[1]))
	perm = input().strip().split()
	for p in range(len(perm)):
		perm[p] = int(perm[p])
	exp = {}
	for j in range(m):
		line = input().strip().split()
		num = int(line[0])
		prob = float(line[1])
		if num in exp:
			exp[num].append(prob)
		else:
			exp[num] = [prob]
	print(handle(exp, perm, n))


def solve(n, m):
	a = list(map(int, input().split()))
	lastCorrectPos = n - 1
	while lastCorrectPos >= 0 and a[lastCorrectPos] == lastCorrectPos + 1:
		lastCorrectPos -= 1
	ans = 1.0
	if lastCorrectPos == -1:
		ans = 0.0
	for _ in range(m):
		data = input().split()
		r = int(data[0]) - 1
		p = float(data[1])
		if r >= lastCorrectPos:
			ans = ans * (1 - p)
	print('{:.6f}'.format(1 - ans))
t = int(input())
for _ in range(t):
	data = input().split()
	solve(int(data[0]), int(data[1]))


from collections import Counter, defaultdict, deque
import math

class newNode:

	def __init__(self, key):
		self.data = key
		self.left = None
		self.right = None

def printSpiral(root):
	h = height(root)
	ltr = False
	for i in range(1, h + 1):
		printGivenLevel(root, i, ltr)
		ltr = not ltr

def printGivenLevel(root, level, ltr):
	if root == None:
		return
	if level == 1:
		print(root.data, end=' ')
	elif level > 1:
		if ltr:
			printGivenLevel(root.left, level - 1, ltr)
			printGivenLevel(root.right, level - 1, ltr)
		else:
			printGivenLevel(root.right, level - 1, ltr)
			printGivenLevel(root.left, level - 1, ltr)

def height(node):
	if node == None:
		return 0
	else:
		lheight = height(node.left)
		rheight = height(node.right)
		if lheight > rheight:
			return lheight + 1
		else:
			return rheight + 1

def solve(n, m, arr, pro):
	for i in range(n, 0, -1):
		if arr[i - 1] == i:
			i -= 1
		else:
			break
	minpos = i
	if minpos == 0:
		return 1
	temp = 1
	ans = 0
	for i in range(0, m):
		if pro[i][0] >= minpos:
			ans += temp * pro[i][1]
			temp *= 1 - pro[i][1]
	return ans
res = []
t = int(input())
for i in range(0, t):
	p = []
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	for i in range(0, m):
		s = input().split()
		p.append([int(s[0]), float(s[1])])
	res.append(solve(n, m, a, p))
for i in range(0, t):
	print(res[i])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	lis = list(map(int, input().split()))
	idx = -1
	for i in reversed(range(n)):
		if lis[i] != i + 1:
			idx = i + 1
			break
	if idx == -1:
		print(1)
		for i in range(m):
			(r, p) = map(float, input().split())
		continue
	ans = 1
	for i in range(m):
		(r, p) = map(float, input().split())
		r = int(r)
		if r >= idx:
			ans *= 1 - p
	print(1 - ans)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	last_unsorted = 0
	for i in range(1, len(a) + 1):
		if a[i - 1] != i:
			last_unsorted = i - 1
	relevants_experiments = []
	for _ in range(m):
		(r, p) = map(float, input().split())
		if r >= last_unsorted + 1:
			relevants_experiments.append(p)
	if last_unsorted == 0:
		print(1)
		continue
	failure = 1
	for p in relevants_experiments:
		failure *= 1 - p
	print(1 - failure)


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa = ifa[::-1]

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] < self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return flag

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		seen.add(u)
		for (v, w) in graph[u]:
			if v not in d or d[v] > d[u] + w:
				d[v] = d[u] + w
				heappush(heap, (d[v], v))
	return d

def GP(it):
	return [[ch, len(list(g))] for (ch, g) in groupby(it)]

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None

def nb(i, j):
	for (ni, nj) in [[i + 1, j], [i - 1, j], [i, j - 1], [i, j + 1]]:
		if 0 <= ni < n and 0 <= nj < m:
			yield (ni, nj)

@bootstrap
def gdfs(r, p):
	if len(g[r]) == 1 and p != -1:
		yield None
	for ch in g[r]:
		if ch != p:
			yield gdfs(ch, r)
	yield None

def f(x):
	fi = bisect_right(a, x)
	b = n - fi
	for i in range(q):
		if k[i] > 0:
			if k[i] > x:
				b += 1
			else:
				fi += 1
		elif -k[i] <= fi:
			fi -= 1
		else:
			b -= 1
	return fi > 0
t = N()
for i in range(t):
	(n, m) = RL()
	a = RLL()
	ma = 0
	for i in range(n - 1, -1, -1):
		if a[i] != i + 1:
			ma = i + 1
			break
	ans = 1
	for i in range(m):
		(r, p) = input().split()
		r = int(r)
		p = float(p)
		if r >= ma:
			ans *= 1 - p
	if not ma:
		print(1)
		continue
	ans = 1 - ans
	print(ans)


from sys import stdin
from sys import stdout
from math import *
for __ in range(int(input())):
	(n, m) = map(int, input().split())
	ar = list(map(int, input().split()))
	d = [0] * (n + 1)
	for i in range(n - 1, -1, -1):
		if ar[i] != i + 1:
			break
		else:
			d[i + 1] = 1
	r = []
	for i in range(m):
		(x, p) = map(float, input().split())
		x = int(x)
		if x == 1:
			continue
		if x == n or d[x + 1] == 1:
			r.append([1, x, p, 1 - p])
		else:
			r.append([0, x, p, 1 - p])
	ans = 0
	s = 0
	for i in range(len(r)):
		if r[i][0] == 1:
			ans += r[i][2]
			if i < len(r) - 1:
				r[i + 1][2] *= r[i][3]
				r[i + 1][3] *= r[i][3]
			s = 1
		elif i < len(r) - 1:
			r[i + 1][2] = r[i + 1][2] * (r[i][3] + r[i][2])
			r[i + 1][3] *= r[i][3] + r[i][2]
	if d[1] == 1:
		ans = 1.0
	print(round(ans, 6))


def computeOrderProb(perm, n, experiments):
	ct = n
	rev = [i + 1 for i in range(n)]
	for i in range(n - 1, -1, -1):
		if perm[i] == rev[i]:
			ct -= 1
		else:
			break
	if ct == 0:
		return 1
	prob = 1
	for exp in experiments:
		(r, p) = exp
		if r >= ct:
			prob = prob * (1 - p)
	return 1 - prob
t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	perm = list(map(int, input().split()))
	experiments = []
	for _ in range(m):
		exp = list(map(float, input().split()))
		exp[0] = int(exp[0])
		experiments.append(exp)
	print(computeOrderProb(perm, n, experiments))


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	req = n
	for i in range(n - 1, -1, -1):
		if arr[i] == i + 1:
			req = i
		else:
			break
	ans = 0
	p = 1
	for i in range(m):
		(x, y) = list(map(float, input().split()))
		x = int(x)
		if x >= req:
			ans += p * y
			p = p * (1 - y)
	if req == 0:
		ans = 1
	print(ans)


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 998244353
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('0')
file = 1

def ceil(a, b):
	return (a + b - 1) // b

def solve():
	for _ in range(ii()):
		(n, m) = mi()
		a = li()
		idx = -1
		for i in range(n, 0, -1):
			if a[i - 1] != i:
				idx = i
				break
		p_not_sorted = 1
		for i in range(m):
			(x, y) = map(float, input().strip().split(' '))
			if x >= idx:
				p_not_sorted *= 1 - y
		if idx == -1:
			print(1)
			continue
		print(1 - p_not_sorted)
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


def proba(arr, po):
	maxi = None
	srt = sorted(arr)
	for i in range(len(arr) - 1, -1, -1):
		if arr[i] != srt[i]:
			maxi = i
			break
	if maxi == None:
		return 1.0
	ans = 1
	for i in range(len(po)):
		if po[i][0] >= maxi:
			ans *= 1 - po[i][1]
	return 1 - ans
for i in range(int(input())):
	(a, b) = map(int, input().strip().split())
	lst = list(map(int, input().strip().split()))
	blanck = []
	for i in range(b):
		(x, y) = map(str, input().strip().split())
		x = int(x) - 1
		y = float(y)
		blanck.append([x, y])
	print(proba(lst, blanck))


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from math import sqrt, pi, ceil, log, inf, gcd, floor
from itertools import combinations, permutations
from bisect import *
from fractions import Fraction

def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		a = list(map(int, input().split()))
		b = [[] for i in range(n)]
		d = sorted(a)
		for i in range(m):
			(x, y) = map(float, input().split())
			b[int(x) - 1].append(y)
		ind = -1
		for i in range(n - 1, -1, -1):
			if d[i] != a[i]:
				ind = i
				break
		if ind == -1:
			print(1)
		else:
			ans = 1
			for i in range(ind, n, 1):
				for j in range(len(b[i])):
					ans *= 1 - b[i][j]
			print(1 - ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def inp():
	return int(input())

def inlt():
	l = input().split()
	for i in range(len(l)):
		l[i] = float(l[i])
	return l

def insr():
	s = input()
	return list(s[:len(s)])
y = inp()
for _ in range(y):
	[n, m] = inlt()
	n = int(n)
	m = int(m)
	l = inlt()
	experiments = []
	for i in range(int(m)):
		experiments.append(inlt())
	k = 0
	while n - k - 1 >= 0:
		if int(l[n - k - 1]) != n - k:
			break
		k += 1
	if k == n:
		res = 1
	else:
		threshold = n - k
		res = 1
		for e in experiments:
			if e[0] >= threshold:
				res *= 1 - e[1]
		res = 1 - res
	print('{:.6f}'.format(res))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [*map(int, input().split())]
	t = 1
	for i in range(n - 1, -1, -1):
		if a[i] != i + 1:
			t = i + 1
			break
	ans = 1
	for i in range(m):
		(r, p) = map(float, input().split())
		if r >= t:
			ans *= 1 - p
	print(1 - ans if t > 1 else 1)


def rand_events(perm_arr, n, exps_arr, m):
	j = find_unsorted_len(perm_arr, n)
	if j == 0:
		return 1.0
	pr = 0.0
	for (ri, pi) in exps_arr:
		if ri - 1 >= j:
			pr = pr + pi - pr * pi
	return pr

def find_unsorted_len(arr, n):
	max_el = arr[0]
	l = 0
	for i in range(n):
		max_el = max(max_el, arr[i])
		if arr[i] < max_el:
			l = i
	return l
t = int(input())
for i in range(t):
	inps = input().split(' ')
	n = int(inps[0])
	m = int(inps[1])
	arr = list(map(lambda x: int(x), input().split(' ')))
	exps = []
	for j in range(m):
		exp_in = input().split(' ')
		exps.append((int(exp_in[0]), float(exp_in[1])))
	print('{0:.6f}'.format(rand_events(arr, n, exps, m)))


import math
from sys import stdin, stdout
input = stdin.readline
for _ in range(int(input())):
	(n, q) = map(int, input().split())
	l = list(map(int, input().split()))
	bk = n + 1
	for i in range(n - 1, -1, -1):
		if l[i] != i + 1:
			bk = i + 1
			break
	ans = 0
	us = 1
	if bk == n + 1:
		ans = 1
	for i in range(q):
		(nd, p) = map(float, input().split())
		ind = int(nd)
		if ind >= bk:
			ans += us * p
			us *= 1 - p
	print(ans)


from math import inf
import sys
import os
from io import BytesIO, IOBase
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	for i in range(n):
		arr[i] -= 1
	target_idx = -1
	for i in range(n - 1, -1, -1):
		if arr[i] != i:
			target_idx = i
			break
	probs = 0
	for i in range(k):
		(idx, p) = map(float, input().split())
		idx = int(idx) - 1
		if idx >= target_idx:
			not_sorted = 1.0 - probs
			now_sorted = not_sorted * p
			probs += now_sorted
	if target_idx < 0:
		probs = 1.0
	print('{:.9f}'.format(probs))


import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	return [[default for j in range(m)] for i in range(n)]

def arr3D(n, m, r, default=0):
	return [[[default for k in range(r)] for j in range(m)] for i in range(n)]

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

class DSU:

	def __init__(self, length):
		self.length = length
		self.parent = [-1] * self.length

	def getParent(self, node, start):
		if node >= self.length:
			return False
		if self.parent[node] < 0:
			if start != node:
				self.parent[start] = node
			return node
		return self.getParent(self.parent[node], start)

	def union(self, node1, node2):
		parent1 = self.getParent(node1, node1)
		parent2 = self.getParent(node2, node2)
		if parent1 == parent2:
			return False
		elif self.parent[parent1] <= self.parent[parent2]:
			self.parent[parent1] += self.parent[parent2]
			self.parent[parent2] = parent1
		else:
			self.parent[parent2] += self.parent[parent1]
			self.parent[parent1] = parent2
		return True

	def getCount(self, node):
		return -self.parent[self.getParent(node, node)]

def exact(num):
	if abs(num - round(num)) <= 10 ** (-9):
		return round(num)
	return num

def solve(n, k, arr, lst):
	index = 0
	arr = arr[::-1]
	for i in range(n - 1):
		if arr[i] != n - i:
			index = i
			break
	index = n - index
	if arr == sorted(arr, reverse=True):
		return 1
	prod = 1
	for i in lst:
		if i[0] >= index:
			prod *= 1 - i[1]
	return 1 - prod
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	lst = []
	for i in range(k):
		lst.append(list(map(float, input().split())))
	print(solve(n, k, arr, lst))


for _ in range(int(input())):
	(n, k) = map(float, input().split(' '))
	arr = list(map(float, input().split(' ')))
	p = 0
	prob = 0
	for i in range(len(arr) - 1, -1, -1):
		if arr[i] != i + 1:
			p = i + 1
			break
	if p == 0:
		prob = 1
	prev = 1
	for i in range(int(k)):
		(r, pi) = map(float, input().split(' '))
		if r >= p:
			prob += prev * pi
			prev = prev * (1 - pi)
	if p == 0:
		print(1)
	else:
		print(prob)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	must = 0
	for i in range(n - 1, -1, -1):
		if a[i] != i + 1:
			must = i + 1
			break
	rp = []
	for _ in range(m):
		(r, p) = input().split()
		rp.append((int(r), float(p)))
	if must == 0:
		result = 1
		print('%.6f' % result)
		continue
	cur = 1
	result = 0
	for (r, p) in rp:
		if must <= r:
			result += cur * p
			cur *= 1 - p
	print('%.6f' % result)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
from itertools import accumulate as ac
mod = int(1000000000.0) + 7
mod = 998244353
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	(n, m) = inp()
	arr = list(inp())
	ct = n
	for i in range(n - 1, -1, -1):
		if arr[i] == ct:
			ct -= 1
		else:
			break
	if ct == 0:
		ans = 1
		for i in range(m):
			(x, p) = list(input().split())
	else:
		ans = 0
		st = 1
		for i in range(m):
			(x, p) = list(input().split())
			x = int(x)
			p = float(p)
			if x >= ct:
				ans += st * p
				st *= 1 - p
	out(ans)


for _ in range(int(input())):
	k = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	c = 0
	for i in range(len(arr) - 1, -1, -1):
		if arr[i] == i + 1:
			c += 1
		else:
			break
	c = len(arr) - c
	n_sorted = float(1)
	for i in range(k[1]):
		q = [x for x in input().split()]
		if int(q[0]) >= c:
			n_sorted *= 1 - float(q[1])
	if not c:
		print('{:.6f}'.format(1.0))
	else:
		print('{:.6f}'.format(1 - n_sorted))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	for i in reversed(range(n)):
		if A[i] != i + 1:
			break
	k = i + 1
	x = 1
	ans = 0
	for i in range(m):
		(r, p) = map(float, input().split())
		r = int(r)
		if r >= k:
			ans += x * p
			x *= 1 - p
		else:
			pass
	if k == 1:
		print(1)
		continue
	print(ans)


def proba(arr, po):
	maxi = None
	for i in range(len(arr) - 1, -1, -1):
		if arr[i] != i + 1:
			maxi = i
			break
	if maxi == None:
		return 1.0
	ans = 1
	po = sorted(po, key=lambda s: s[0], reverse=True)
	for i in range(len(po)):
		if po[i][0] >= maxi:
			ans *= 1 - po[i][1]
		else:
			break
	return 1 - ans
for i in range(int(input())):
	(a, b) = map(int, input().strip().split())
	lst = list(map(int, input().strip().split()))
	blanck = []
	for i in range(b):
		(x, y) = map(str, input().strip().split())
		x = int(x) - 1
		y = float(y)
		blanck.append([x, y])
	print(proba(lst, blanck))


test = int(input())
for t in range(0, test):
	(n, m) = [int(i) for i in input().split(' ')]
	a = [int(i) for i in input().split(' ')]
	max_sorted = n
	for i in reversed(range(0, n)):
		if a[i] == i + 1:
			max_sorted -= 1
		else:
			break
	pa = 0
	pb = 1
	for i in range(0, m):
		(r, p) = [float(i) for i in input().split(' ')]
		if r >= max_sorted:
			pa += pb * p
			pb *= 1 - p
	if max_sorted == 0:
		print(1)
	else:
		print(pa)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	x = n
	for i in range(n - 1, -1, -1):
		if x != a[i]:
			break
		x -= 1
	ans = 1
	for _ in range(m):
		(i, p) = list(map(float, input().split()))
		if int(i) >= x:
			ans *= 1 - p
	if a == sorted(a):
		print(1)
		continue
	print('%.15f' % (1 - ans))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = []
	for j in range(m):
		(l, h) = map(float, input().split())
		b.append([int(l), h])
	b.sort()
	j = n - 1
	f = True
	k = 0
	while j > 0 and f:
		if a[j] - 1 != j:
			f = False
			k = j + 1
		j -= 1
	p = []
	i = 0
	sas = []
	while i < m:
		if b[i][0] >= k:
			sas.append(b[i][1])
		i += 1
	ans = 1
	for i in range(len(sas)):
		ans *= 1 - sas[i]
	if sorted(a) == a:
		print(1.0)
	else:
		print(1 - ans)


T = int(input())
t = 1
while t <= T:
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	manlist = []
	for i in range(m):
		(r, p) = map(float, input().split())
		manlist.append([int(r), p])
	ans = 0
	end = n - 1
	while end > 0 and arr[end] == end + 1:
		end -= 1
	if end == 0:
		ans = 1.0
	else:
		notsorted = 1.0
		for man in manlist:
			if man[0] > end:
				notsorted *= 1.0 - man[1]
		ans = 1.0 - notsorted
	print(ans)
	t += 1


for _ in range(int(input())):
	(n, m) = map(int, input().split(' '))
	arr = [int(w) for w in input().split(' ')]
	p = 0
	for i in range(1, n + 1):
		if i != arr[i - 1]:
			p = i
	ans = 1
	if p == 0:
		for _ in range(m):
			(u, x) = map(float, input().split(' '))
			u = int(u)
			if u >= p:
				ans = ans * (1 - x)
		print(1.0)
	else:
		for _ in range(m):
			(u, x) = map(float, input().split(' '))
			u = int(u)
			if u >= p:
				ans = ans * (1 - x)
		print(1 - ans)


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from itertools import accumulate
from functools import reduce, cmp_to_key, lru_cache
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import sys
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip().split()]

def st():
	return str(input().rstrip())[2:-1]

def val():
	return int(input().rstrip())

def li2():
	return [str(i)[2:-1] for i in input().rstrip().split()]

def li3():
	return [int(i) for i in st()]
for _ in range(val()):
	(n, m) = li()
	l = li()
	ma = n
	l1 = sorted(l)
	for i in range(n - 1, -1, -1):
		if l[i] == l1[i]:
			ma -= 1
		else:
			break
	ans = float('inf')
	pro = 1
	if ma == 0:
		pro = 0
	for i in range(m):
		(a, b) = li2()
		a = int(a)
		b = float(b)
		if a >= ma:
			pro *= 1 - b
	print(1 - pro)


from queue import LifoQueue

def print_sol(c, sol):
	print('Case #{}: {}'.format(c, sol))

def rd_int():
	return int(input())

def rd_str():
	return input()

def rd_str_lst():
	return input().split(' ')

def sp_str_lst():
	return list(input())

def rd_int_lst():
	return [int(i) for i in rd_str_lst()]

def rd_float_lst():
	return [float(i) for i in rd_str_lst()]

def sp_int_lst():
	return [int(i) for i in sp_str_lst()]

def dfs(g, i, v):
	v[i] = True
	for j in g[i]:
		if not v[j]:
			dfs(g, j, v)
	print(i)

def dfs_iter(g, i, n):
	v = [False] * n
	stack = LifoQueue()
	stack.put(i)
	while stack.not_empty:
		u = stack.get()
		v[u] = True
		print(u)
		for i in g[u]:
			if not v[i]:
				stack.put(i)

def happiness(g, i, v, p, h, f):
	au = p[i]
	gv = 0
	v[i] = True
	for j in g[i]:
		if not v[j]:
			(av, gvi, f) = happiness(g, j, v, p, h, f)
			au += av
			gv += gvi
	if not (au + h[i]) % 2 == 0:
		f = False
	gu = (au + h[i]) // 2
	if not 0 <= gu <= au:
		f = False
	if not gu >= gv:
		f = False
	return (au, gu, f)

def main():
	t = rd_int()
	for _ in range(1, t + 1):
		(n, m) = rd_int_lst()
		a = rd_int_lst()
		sp = [rd_float_lst() for i in range(m)]
		x = n
		while a[x - 1] == x and x > 0:
			x -= 1
		if x == 0:
			print(1)
			continue
		p = 1
		s = 0
		for i in range(m):
			if sp[i][0] >= x:
				s += p * sp[i][1]
				p *= 1 - sp[i][1]
		print(s if p < 1 else 0)
main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	ans = 0
	prev = 1
	f = 0
	pos = 0
	for i in range(n - 1, -1, -1):
		if arr[i] != i + 1:
			pos = i + 1
			break
	if pos == 0:
		f = 1
		f_ans = 1
	for i in range(m):
		temp = input().split()
		l = int(temp[0])
		prob = float(temp[1])
		if l >= pos:
			ans += prev * prob
			prev *= 1 - prob
			if prev == 0:
				f = 1
				f_ans = ans
	if f:
		print(f_ans)
	else:
		print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ls = list(map(int, input().split()))
	i = n - 1
	while i >= 0:
		if ls[i] != i + 1:
			break
		i -= 1
	i += 1
	f = 0
	if i == 0:
		print(1)
		f = 1
	ans = []
	for _ in range(m):
		(a, b) = input().split()
		if int(a) >= i:
			ans.append(float(b))
	c = 0
	for i in ans:
		c -= c * i
		c += i
	if f == 0:
		print(c)


T = int(input())

def func(arr, n, m, rp):
	final = ''
	largeMisplaced = n
	while largeMisplaced >= 1 and arr[largeMisplaced - 1] == largeMisplaced:
		largeMisplaced -= 1
	if largeMisplaced == 0:
		print('1.000000')
		return
	prod = 1
	for i in range(m):
		(r, p) = rp[i]
		if r >= largeMisplaced:
			prod *= 1 - p
	final = 1 - prod
	final = str(final)
	if len(final) == 1:
		final += '.000000'
	else:
		temp = 8 - len(final)
		final = final + '0' * temp
	print(final)
for t in range(T):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	arr = [int(i) for i in input().split()]
	rp = []
	for i in range(m):
		(r, p) = input().split()
		r = int(r)
		p = float(p)
		rp.append([r, p])
	func(arr, n, m, rp)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = 1
	c = 0
	f = 1
	for i in range(n - 1, -1, -1):
		if a[i] != i + 1:
			f = 0
			break
	i += 1
	for j in range(m):
		(x, y) = input().split()
		x = int(x)
		y = float(y)
		if x >= i:
			c += b * y
			b *= 1 - y
	if f:
		print('%.6f' % 1)
	else:
		print('%.6f' % c)


import sys, math
from functools import reduce
N = int(input())
for i in range(N):
	(n, m) = list(map(int, sys.stdin.readline().strip().split()))
	arr = list(map(int, sys.stdin.readline().strip().split()))
	lmt = n
	for pos in range(n - 1, -1, -1):
		if arr[pos] == pos + 1:
			lmt -= 1
		else:
			break
	P = []
	for _ in range(m):
		(a, b) = list(map(float, sys.stdin.readline().strip().split()))
		if int(a) >= lmt:
			P.append(b)
	if lmt == 0:
		print(1.0)
	elif len(P) == 0:
		print(0.0)
	else:
		print(1 - reduce(lambda x, y: x * y, map(lambda x: 1 - x, P)))


t = int(input().strip())
for _ in range(t):
	(n, m) = map(int, input().strip().split())
	a = list(map(int, input().strip().split()))
	lastUnsorted = n - 1
	while lastUnsorted >= 0 and a[lastUnsorted] == lastUnsorted + 1:
		lastUnsorted = lastUnsorted - 1
	s = 1
	for z in range(m):
		(idx, p) = map(float, input().strip().split())
		if idx >= lastUnsorted + 1:
			s = s * (1 - p)
	if lastUnsorted == -1:
		print('{:.6f}'.format(1))
	else:
		print('{:.6f}'.format(1 - s))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for j in range(int(input())):
	(n, m) = map(int, input().split())
	vals = list(map(int, input().split()))
	ind = 10 ** 9
	test = []
	for s in range(n - 1, -1, -1):
		if vals[s] == s + 1:
			continue
		else:
			ind = s
			break
	mult = 1
	for s in range(m):
		info = input().split()
		pref = int(info[0])
		prob = float(info[1])
		if pref >= ind + 1:
			mult *= 1 - prob
	if ind == 10 ** 9:
		print(1)
	else:
		print(1 - mult)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	prob = []
	for i in range(m):
		(a, b) = map(float, input().split())
		a = int(a)
		prob.append([a, b])
	cur = n - 1
	while cur >= 0:
		if l[cur] != cur + 1:
			break
		else:
			cur -= 1
	if cur == -1:
		print('{:.6f}'.format(1))
		continue
	cur += 1
	p = 1.0
	ans = 0
	for i in range(m):
		if prob[i][0] >= cur:
			ans += p * prob[i][1]
			p *= 1 - prob[i][1]
	print('{:.6f}'.format(ans))


import sys
from math import *
from collections import deque, Counter

def linp():
	return list(map(int, sys.stdin.readline().split()))

def minp():
	return map(int, sys.stdin.readline().split())

def sinp():
	return sys.stdin.readline().rstrip('\n')

def inp():
	return int(sys.stdin.readline())
for t in range(inp()):
	(n, m) = minp()
	lst = linp()
	marr = []
	melem = lst[0]
	for i in range(n):
		melem = max(melem, lst[i])
		marr.append(melem)
	ust = n
	for i in range(n - 1, -1, -1):
		if lst[i] == i + 1:
			ust -= 1
		else:
			break
	ans = 0
	for i in range(m):
		s = sinp().split()
		(r, p) = (int(s[0]), float(s[1]))
		if r >= ust:
			if ans == 0:
				ans = p
			else:
				ans = ans + p - ans * p
	print('{:.6f}'.format(1 if ust == 0 else ans))


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, M, A, RP):
	sA = sorted(A)
	longest = 0
	while longest < N and A[N - 1 - longest] == sA[N - 1 - longest]:
		longest += 1
	if longest == N:
		return 1.0
	bad = 1.0
	for (r, p) in RP:
		r = int(r)
		p = float(p)
		if r >= N - longest:
			bad *= 1.0 - p
	return 1.0 - bad
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N, M) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	RP = [[x for x in input().split()] for i in range(M)]
	ans = solve(N, M, A, RP)
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	(n, m) = map(int, input().split())
	lst = list(map(int, input().split()))
	lst.reverse()
	k = n
	for i in lst:
		if i == k:
			k -= 1
		else:
			break
	ans = 1.0
	for i in range(m):
		(r, p) = map(float, input().split())
		if r >= k:
			ans *= 1.0 - p
	if k == 0:
		print(1)
	else:
		print('{:.6f}'.format(1.0 - ans))


for testcase in range(int(input())):
	(n, m) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	b = n - 1
	while a[b] == b + 1:
		b -= 1
	cnt = 1
	for i in range(m):
		c = input().split(' ')
		ri = int(c[0])
		pi = float(c[1])
		cnt *= 1 - pi * (ri > b)
	if b == -1:
		print(1.0)
	else:
		print(1 - cnt)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	e = sorted(a)
	cnt = 0
	for j in range(n):
		if e[-j - 1] == a[-j - 1]:
			cnt += 1
		else:
			break
	a = n - cnt
	if a == 0:
		print(1)
		for i in range(k):
			(p, r) = input().split()
			p = int(p)
			r = float(r)
	else:
		current = 0
		for i in range(k):
			(p, r) = input().split()
			p = int(p)
			r = float(r)
			if p >= a:
				current += (1 - current) * r
		print(current)


from collections import defaultdict, deque, Counter, OrderedDict
import sys
from bisect import bisect_left

def main():
	t = int(input())
	while t:
		t -= 1
		(n, m) = [int(i) for i in input().split()]
		arr = [int(i) for i in input().split()]
		is_sorted = [False] * n
		if arr[-1] == n:
			is_sorted[-1] = True
		for i in range(n - 2, -1, -1):
			if is_sorted[i + 1] and arr[i] == i + 1:
				is_sorted[i] = True
			else:
				break
		ans = []
		for i in range(m):
			(a, b) = input().split()
			(a, b) = (int(a), float(b))
			if a == n or is_sorted[a]:
				ans.append((b, 1 - b))
		if is_sorted[0]:
			print(1)
			continue
		if len(ans) == 0:
			print(0)
			continue
		res = ans[0][0]
		for i in range(1, len(ans)):
			current = ans[i][0]
			res += (1 - res) * current
		print(res)
main()


import sys
input = sys.stdin.readline
ri = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rs = lambda : input().strip('\r\n')
for _ in range(ri()):
	(n, m) = rl()
	a = rl()
	pos = n - 1
	while a[pos] == pos + 1 and pos >= 0:
		pos -= 1
	ans = 1
	if pos == -1:
		ans = 0
	for _ in range(m):
		(r, p) = input().split()
		r = int(r) - 1
		p = float(p)
		if r >= pos:
			ans = ans * (1 - p)
	print(1 - ans)


t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	l = n
	ans = 1
	while l:
		if a[l - 1] != l:
			break
		l -= 1
	while m:
		m -= 1
		(p, r) = input().split()
		p = int(p)
		r = float(r)
		if p >= l:
			ans *= 1 - r
	if l == 0:
		print(format(1, '.6f'))
	else:
		print(format(1 - ans, '.6f'))


import sys
import functools

def sip():
	return sys.stdin.readline().rstrip()

def gen_test_cases():
	num_tests = int(sip())
	for i in range(num_tests):
		(dlen, nexp) = map(int, sip().split(' '))
		data = list(map(int, sip().split(' ')))
		exps = [(int(t[0]), float(t[1])) for t in [sip().split(' ') for _ in range(nexp)]]
		yield (dlen, data, nexp, exps)
for (dlen, data, nexp, exps) in gen_test_cases():
	mata = [n if data[n] == n + 1 else 0 for n in range(dlen)]
	m = functools.reduce(lambda b, a: (1, a) if b[0] and a else (0, b[1]), reversed(mata), (1, dlen))
	fes = list(filter(lambda a: a[0] >= m[1], exps))
	ps = list(map(lambda a: a[1], fes))
	r = 0.0 if m[1] == 1 else functools.reduce(lambda b, a: b * (1.0 - a), ps, 1.0)
	print(1.0 - r)


import sys
import math
t = int(input().strip())
for a0 in range(t):
	l = [int(i) for i in input().split()]
	n = l[0]
	k = l[1]
	l1 = [int(i) for i in input().split()]
	c = 0
	flg = 0
	for i in range(len(l1) - 1):
		if l1[i] > l1[i + 1]:
			break
		else:
			c += 1
	if c == len(l1) - 1:
		flg = 1
	brk = 0
	for i in range(n - 1, -1, -1):
		if l1[i] != i + 1:
			brk = i + 1
			break
	res = 1
	for i in range(k):
		l2 = [float(i) for i in input().split()]
		a = l2[0]
		p = l2[1]
		if a >= brk:
			res = res * (1 - p)
	if flg == 1:
		print(1)
	else:
		print(1 - res)


t = int(input())
while t != 0:
	(n, m) = map(int, input().split())
	list1 = list(map(int, input().split()))
	idx = -1
	for i in range(n - 1, -1, -1):
		if list1[i] == i + 1:
			pass
		else:
			idx = i
			break
	if idx == -1:
		ans = 0
	else:
		ans = 1
	for i in range(m):
		(a, b) = input().split()
		a = int(a) - 1
		b = float(b)
		if a >= idx:
			ans = ans * (1 - b)
	print('%.6f' % (1 - ans))
	t -= 1


t = int(input())
for tc in range(t):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	a = [int(x) for x in input().split()]
	res = -1
	for k in range(n):
		if k + 1 != a[k]:
			res = k
	if res == -1:
		for j in range(m):
			line = input()
		print('1')
	else:
		probs = []
		for j in range(m):
			(ii, jj) = input().split()
			ii = int(ii)
			jj = float(jj)
			if ii > res:
				probs.append(jj)
		probs.sort()
		ans = 0.0
		fail = 1.0
		for p in probs:
			ans += fail * p
			fail *= 1 - p
		print('{:0.10f}'.format(ans))


t = int(input())
for z in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	curr_correct = n + 1
	for i in range(n, 0, -1):
		if l[i - 1] == i:
			curr_correct = i
		else:
			break
	all_fail = 1
	for i in range(m):
		(r, p) = input().split()
		r = int(r)
		p = float(p)
		if r >= curr_correct - 1:
			all_fail *= 1 - p
	if curr_correct == 1:
		print(1)
		continue
	print('{0:.7f}'.format(1 - all_fail))


import sys

def main():

	def modst(a, s):
		ret = 1
		while s:
			if s % 2:
				ret = ret * a % mod
			a = a * a % mod
			s //= 2
		return ret

	def Cnk(n, k):
		return (k <= n and n >= 0) * (f[n] * modst(f[k] * f[n - k] % mod, mod - 2) % mod)
	(n, m) = map(int, sys.stdin.readline().split())
	q = list(map(int, sys.stdin.readline().split()))
	(p, ans, i) = (n, 1, n - 1)
	while i > -1 and q[i] == i + 1:
		(p, i) = (i, i - 1)
	for i in range(m):
		(a, b) = map(float, input().split())
		if a >= p:
			ans = ans * (1 - b)
	print(1 - ans if p != 0 else 1)
for i in range(int(input())):
	main()


def solve(n, m):
	a = list(map(int, input().split()))
	idx = n - 1
	while idx >= 0 and a[idx] == idx + 1:
		idx -= 1
	ans = 1.0
	if idx == -1:
		ans = 0.0
	for i in range(m):
		inp = input().split()
		r = int(inp[0]) - 1
		p = float(inp[1])
		if r >= idx:
			ans = ans * (1 - p)
	print('{:.6f}'.format(1 - ans))
t = int(input())
for _ in range(t):
	inp = input().split()
	solve(int(inp[0]), int(inp[1]))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	ans = 1
	s = -1
	for i in range(len(arr)):
		if arr[i] == i + 1:
			continue
		else:
			s = i
	for i in range(m):
		(k, p) = map(float, input().split())
		if int(k) > s:
			ans *= 1 - p
	if arr == sorted(arr):
		ans = 0
	print(1 - ans)


import sys

def solve(perm, experiments):
	longest_unsorted_prefix_len = 0
	for i in reversed(range(len(perm))):
		if perm[i] != i + 1:
			longest_unsorted_prefix_len = i + 1
			break
	if longest_unsorted_prefix_len:
		prod = 1
		for (pref_len, p) in experiments:
			if pref_len >= longest_unsorted_prefix_len:
				prod *= 1 - p
		print(1 - prod)
	else:
		print(1)
first = True
at_perm = False
n_exps = 0
perm = None
experiments = []
for line in sys.stdin:
	if first:
		first = False
		continue
	terms = line.split(' ')
	if at_perm:
		perm = [int(n) for n in terms]
		at_perm = False
	elif n_exps:
		experiments.append((int(terms[0]), float(terms[1])))
		n_exps -= 1
	else:
		if perm:
			solve(perm, experiments)
		experiments = []
		(_, n_exps) = [int(n) for n in terms]
		at_perm = True
if perm:
	solve(perm, experiments)


test_num = int(input())

def solve():
	(n, m) = map(int, input().split())
	permutation = list(map(int, input().split()))
	pos = len(permutation) - 1
	while pos > -1 and permutation[pos] == pos + 1:
		pos -= 1
	nPossibility = 1
	for i in range(m):
		exp = input().split()
		r = int(exp[0])
		p = float(exp[1])
		if r >= pos + 1:
			nPossibility *= 1 - p
	if pos == -1:
		print(1.0)
	else:
		print(1 - nPossibility)
for i in range(test_num):
	solve()


t = int(input())
for _ in range(t):
	inp = input().split()
	n = int(inp[0])
	m = int(inp[1])
	arr = list(map(int, input().split()))
	last = -1
	for i in range(0, n):
		if arr[i] != i + 1:
			last = i + 1
	ans = 1.0
	for _ in range(m):
		data = input().split()
		r = int(data[0])
		p = float(data[1])
		if r >= last:
			ans = ans * (1 - p)
	if last == -1:
		print(1.0)
	else:
		print('{:.6f}'.format(1 - ans))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ar = list(map(int, input().split()))
	val = n
	for i in ar[::-1]:
		if i != val:
			break
		val -= 1
	tmp = 0
	for i in range(m):
		(xx, yy) = map(float, input().split())
		if xx >= val:
			vall = tmp
			tmp += yy
			tmp -= yy * vall
	if val == 0:
		print(1)
	else:
		print(tmp)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	for i in range(n, 0, -1):
		if l[i - 1] != i:
			break
	z = i
	flag = 0
	if z == 1:
		print(1)
		flag = 1
	ans = 1
	for i in range(m):
		(a, b) = map(float, input().split())
		if a >= z:
			ans *= 1 - b
	if flag == 0:
		print('{:.6f}'.format(1 - ans))


t = int(input())
for u in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	i = n - 1
	while i > 0:
		if a[i] != i + 1:
			break
		i -= 1
	ans = False
	if i == 0:
		ans = True
	old = 0
	i += 1
	for x in range(m):
		(j, p) = map(float, input().split())
		if j >= i:
			temp = old
			old += p
			old -= p * temp
	if ans:
		print(1)
	else:
		print(old)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = [int(i) for i in input().split()]
	ns = -1
	for i in range(n - 1, -1, -1):
		if l[i] != i + 1:
			ns = i + 1
			break
	ans = 1
	ans = 1
	while m > 0:
		(r, p) = map(float, input().split())
		if ns != -1 and int(r) >= ns or int(r) == n:
			ans = ans * (1 - p)
		m = m - 1
	if ns == -1:
		ans = 1
		print('%.6f' % ans)
		continue
	ans = 1 - ans
	print('%.6f' % ans)


import sys
import time
import os
from math import sqrt, log, log2, ceil, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial
from copy import copy, deepcopy
from sys import exit, stdin, stdout
from collections import Counter, defaultdict, deque
from itertools import permutations
import heapq
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007
iinp = lambda : int(sys.stdin.readline())
inp = lambda : sys.stdin.readline().strip()
strl = lambda : list(inp().strip().split(' '))
intl = lambda : list(map(int, inp().split(' ')))
mint = lambda : map(int, inp().split())
fint = lambda : map(float, inp().split())
flol = lambda : list(map(float, inp().split(' ')))
flush = lambda : stdout.flush()

def permute(nums):

	def fun(arr, nums, cur, v):
		if len(cur) == len(nums):
			arr.append(cur.copy())
		i = 0
		while i < len(nums):
			if v[i]:
				i += 1
				continue
			else:
				cur.append(nums[i])
				v[i] = 1
				fun(arr, nums, cur, v)
				cur.pop()
				v[i] = 0
				i += 1
		return arr
	res = []
	nums.sort()
	v = [0] * len(nums)
	return fun(res, nums, [], v)

def subsets(res, index, arr, cur):
	res.append(cur.copy())
	for i in range(index, len(arr)):
		cur.append(arr[i])
		subsets(res, i + 1, arr, cur)
		cur.pop()
	return res

def sieve(N):
	root = int(sqrt(N))
	primes = [1] * (N + 1)
	(primes[0], primes[1]) = (0, 0)
	for i in range(2, root + 1):
		if primes[i]:
			for j in range(i * i, N + 1, i):
				primes[j] = 0
	return primes

def bs(arr, l, r, x):
	if x < arr[0] or x > arr[len(arr) - 1]:
		return -1
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	p = int(sqrt(n))
	for i in range(5, p + 1, 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def solve():
	(n, m) = mint()
	arr = intl()
	i = n - 1
	ans = 1
	flag = 0
	while i >= 0:
		if arr[i] != i + 1:
			break
		i -= 1
	if i == -1:
		flag = 1
	for j in range(m):
		(r, p) = fint()
		if r - 1 >= i:
			ans *= 1 - p
	print(1 - ans) if not flag else print(1)
start_time = time.time()
for _ in range(iinp()):
	solve()


from sys import stdin, stdout
from collections import *
from math import gcd, floor, ceil

def st():
	return list(stdin.readline().strip())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def inp():
	return int(stdin.readline())

def pr(n):
	return stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')

def solve():
	(n, q) = mp()
	l = li()
	c = 0
	x = []
	for i in range(q):
		(a, b) = input().split()
		b = float(b)
		a = int(a)
		x.append((a, b))
	if sorted(l) == l:
		pr(1)
		return
	p = n - 1
	k = n
	v = []
	while p >= 0:
		if l[p] != k:
			break
		else:
			p -= 1
			k -= 1
	p += 1
	for i in range(q):
		(x1, y1) = x[i]
		if x1 >= p:
			v.append(y1)
	ans = 1
	for i in v:
		ans *= 1 - i
	pr(1 - ans)
for _ in range(inp()):
	solve()


from functools import reduce
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	data = list(map(int, input().split()))
	p = -1
	for j in range(n - 1, -1, -1):
		if data[j] != j + 1:
			p = j + 1
			break
	res = []
	for j in range(m):
		(a, b) = input().split()
		a = int(a)
		b = float(b)
		if a >= p:
			res.append(1 - b)
	if p == -1:
		print(1.0)
	elif len(res) == 0:
		print(0)
	else:
		print(1 - reduce(lambda x, y: x * y, res))


import sys
input = sys.stdin.readline
for i in range(int(input())):
	(n, m) = map(int, input().split())
	r = [0] * m
	p = [0] * m
	a = list(map(int, input().split()))
	for i in range(m):
		(r[i], p[i]) = input().split()
		r[i] = int(r[i])
		p[i] = float(p[i])
	res = 0
	prob = 1
	pre = [False] * n
	post = [False] * n
	for i in range(n - 1, -1, -1):
		if a[i] == i + 1:
			post[i] = True
		else:
			break
	for i in range(n):
		if a[i] == i + 1:
			pre[i] = True
		else:
			break
	for i in range(m):
		if r[i] == n or post[r[i]] == True:
			if pre[r[i] - 1] == False:
				res += prob * p[i]
				prob = prob * (1 - p[i])
			else:
				res += prob
				break
	print(res)
	continue


R = lambda : map(int, input().split())
(t,) = R()
for _ in [0] * t:
	(n, m) = R()
	a = (1, *R())
	while a[n] == n:
		n -= 1
	q = n > 0
	for _ in [0] * m:
		(r, p) = input().split()
		q *= 1 - float(p) * (int(r) >= n)
	print(1 - q)


from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	p = -1
	for i in range(n - 1, -1, -1):
		if a[i] != i + 1:
			break
		p = i
	ans = 0
	b = 1
	for i in range(m):
		(x, y) = input().split()
		x = int(x)
		y = float(y)
		if p == -1:
			if x == n:
				b = 0
				ans += y * (1 - ans)
		elif x >= p:
			b = 0
			ans += y * (1 - ans)
	if a == sorted(a):
		print(1)
		continue
	print(ans)


import sys, math, itertools, collections, copy
input = sys.stdin.readline

def solve():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	(prob, r) = (1.0, -1)
	for i in range(n):
		if a[i] != i + 1:
			r = i
	for i in range(m):
		(r1, prob1) = input().split()
		(r1, prob1) = (int(r1), float(prob1))
		if r1 - 1 >= r:
			prob *= 1 - prob1
	if r == -1:
		print(1.0)
		return
	print(1.0 - prob)
for _ in range(int(input())):
	solve()


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def soln(arr, ps):
	last_unsolved = 0
	for (i, item) in enumerate(arr):
		if item != i + 1:
			last_unsolved = i + 1
	if last_unsolved == 0:
		return 1.0
	prob = 0.0
	for test in ps:
		if test[0] < last_unsolved:
			continue
		prob = 1.0 - (1 - prob) * (1 - test[1])
	return prob
tests = inp()
for test in range(tests):
	mn = inlt()
	arr = inlt()
	assert len(arr) == mn[0]
	ps = []
	for n in range(mn[1]):
		temp = input().split(' ')
		temp[0] = int(temp[0])
		temp[1] = float(temp[1])
		ps.append(temp)
	print(soln(arr, ps))


from sys import stdin, stdout
import math, bisect
from collections import Counter, deque, defaultdict
L = lambda : list(map(int, stdin.readline().strip().split()))
M = lambda : map(int, stdin.readline().strip().split())
I = lambda : int(stdin.readline().strip())
S = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()

def pr(a):
	return ''.join(list(map(str, a)))

def solve():
	(n, m) = M()
	a = L()
	b = a.copy()
	b.sort()
	ar = []
	for i in range(m):
		ar += [C()]
	if a == b:
		print(1)
		return
	for i in range(n - 1, -1, -1):
		if a[i] != b[i]:
			break
	x = i
	ans = 0
	b = 0
	for i in range(m):
		r = int(ar[i][0])
		p = float(ar[i][1])
		if r >= x + 1:
			if b:
				te = ans
				ans += p
				ans -= te * p
			else:
				ans = p
			b += 1
	if b:
		print(ans)
	else:
		print(0)
for _ in range(I()):
	solve()


t = int(input())
for asd in range(t):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	br = []
	for i in range(1, n + 1):
		br.append(i)
	idx = n - 1
	while idx >= 0:
		if ar[idx] != br[idx]:
			break
		idx -= 1
	ans = 1.0
	if idx <= 0:
		ans = 1.0
		for i in range(k):
			(a, p) = input().split()
	else:
		for i in range(k):
			(a, p) = input().split()
			a = int(a)
			p = float(p)
			a -= 1
			if a >= idx:
				ans = ans * (1.0 - p)
		ans = 1 - ans
	print('%.9f' % ans)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split(' '))
	nums = list(map(int, input().split(' ')))
	mat = []
	for i in range(m):
		lst = list(map(float, input().split(' ')))
		mat.append(lst)
	index = 0
	for i in range(n - 1, 0, -1):
		if nums[i] != i + 1:
			index = i
			break
	if index == 0:
		print(1)
		continue
	prob = 0
	mul = 1
	for i in range(m):
		if mat[i][0] >= index + 1:
			prob = prob + mul * mat[i][1]
			mul = mul * (1 - mat[i][1])
	print(prob)


def solve():
	(n, m) = map(int, input().split())
	permutation = list(map(int, input().split()))
	experiments = list((list(map(float, input().split())) for _ in range(m)))
	index = next((i for i in reversed(range(n)) if permutation[i] != i + 1), -1)
	if index < 0:
		return 1.0
	experiments = list(filter(lambda e: e[0] > index, experiments))
	result = 0
	unsuccessful = 1
	for (_, p) in experiments:
		result += unsuccessful * p
		unsuccessful *= 1 - p
	return result
for _ in range(int(input())):
	print(solve())


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	x = 0
	for i in range(n):
		if arr[i] != i + 1:
			x = i
	x += 1
	out = 1
	for q in range(m):
		inp = input().split()
		if int(inp[0]) >= x:
			out *= 1 - float(inp[1])
	if arr == sorted(arr):
		print('%.9f' % 1)
	else:
		out = 1 - out
		print('%.9f' % out)


from sys import stdin
import sys
tt = int(stdin.readline())
for loop in range(tt):
	(n, m) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	pr = []
	for i in range(m):
		(r, p) = stdin.readline().split()
		pr.append((float(p), int(r)))
	for i in range(n - 1, -1, -1):
		if a[i] != i + 1:
			over = i + 1
			break
	else:
		print(1)
		continue
	nable = 1
	for (p, r) in pr:
		if r >= over:
			nable *= 1 - p
	print(1 - nable)


t = int(input())
for case in range(t):
	(n, m) = [int(x) for x in input().split(' ')]
	a = [int(x) for x in input().split(' ')]
	x = []
	for i in range(m):
		u = input().split(' ')
		u = [int(u[0]), float(u[1])]
		x.append(u)
	f = 0
	for i in range(n):
		if a[i] != i + 1:
			f = i + 1
	if f == 0:
		ans = 1
	else:
		x = [y for y in x if y[0] >= f]
		ans = 0
		r = 1
		for z in x:
			ans += r * z[1]
			r *= 1 - z[1]
	print(ans)


from sys import stdin, stdout
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import *
from random import *
input = stdin.readline
prin = stdout.write
from random import sample
from collections import Counter, deque
from fractions import *
from math import sqrt, ceil, log2, gcd
mod = 10 ** 9 + 7

def f(arr, i, j, d, dist):
	if i == j:
		return
	nn = max(arr[i:j])
	for tl in range(i, j):
		if arr[tl] == nn:
			dist[tl] = d
			f(arr, i, tl, d + 1, dist)
			f(arr, tl + 1, j, d + 1, dist)

def ps(n):
	cp = 0
	lk = 0
	arr = {}
	while n % 2 == 0:
		n = n // 2
		lk += 1
	for ps in range(3, ceil(sqrt(n)) + 1, 2):
		lk = 0
		cc = 0
		while n % ps == 0:
			n = n // ps
			lk += 1
	if n != 1:
		lk += 1
		return False
	return True

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def factorials(n, r):
	slr = n
	dpr = r
	qlr = 1
	qs = 1
	mod = 10 ** 9 + 7
	for ip in range(n - r + 1, n + 1):
		qlr = qlr * ip % mod
	for ij in range(1, r + 1):
		qs = qs * ij % mod
	ans = qlr * modInverse(qs) % mod
	return ans

def modInverse(b):
	qr = 10 ** 9 + 7
	return pow(b, qr - 2, qr)
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def power(arr):
	listrep = arr
	subsets = []
	for i in range(2 ** len(listrep)):
		subset = []
		for k in range(len(listrep)):
			if i & 1 << k:
				subset.append(listrep[k])
		subsets.append(subset)
	return subsets

def pda(n):
	list = []
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				list.append(i)
			else:
				list.append(n // i)
				list.append(i)
	return list

def dis(xa, ya, xb, yb):
	return sqrt((xa - xb) ** 2 + (ya - yb) ** 2)

def ii():
	return int(input())

def ilist():
	return [int(x) for x in input().strip().split()]

def islist():
	return list(map(str, input().split().rstrip()))

def inp():
	return input().strip()

def google(test, ans):
	return 'Case #' + str(test) + ': ' + str(ans)

def overlap(x1, y1, x2, y2):
	if x2 > y1:
		return y1 - x2
	if y1 > y2:
		return y2 - x2
	return y1 - x2
t = int(input())
for p in range(t):
	(n, m) = ilist()
	arr = ilist()
	kl = set()
	for j in range(n - 1, -1, -1):
		if arr[j] != j + 1:
			for ip in range(j, n):
				kl.add(ip + 1)
			break
	prod = 1
	pp = 0
	for i in range(m):
		(x, y) = input().strip().split()
		x = int(x)
		y = float(y)
		if x in kl:
			prod *= 1 - y
			pp = 1
	if len(kl) == 0:
		print(1)
		continue
	print(1 - prod)


from sys import stdin
from math import pi
input = lambda : stdin.readline().strip()
ipnut = input
pprint = lambda x: print(' '.join(map(str, x)))
yes = 'YES'
no = 'NO'
queQue = int(input())
for i in range(queQue):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	minr = n
	for i in range(n):
		if a[-1 - i] == n - i:
			minr = n - i - 1
		else:
			break
	ans = 1
	for i in range(m):
		sol = input().split()
		r = int(sol[0])
		p = 1 - float(sol[1])
		if r >= minr:
			ans *= p
	if minr == 0:
		print(1)
		continue
	print(1 - ans)


for _ in range(int(input())):
	(N, M) = map(int, input().split())
	A = list(map(int, input().split()))
	req = N
	while req > 0 and A[req - 1] == req:
		req -= 1
	ans = 1
	f = 0
	for i in range(M):
		(idx, prob) = input().split()
		if int(idx) >= req:
			f = 1
			ans *= 1 - float(prob)
	if req == 0:
		print(1)
	elif f:
		print(1 - ans)
	else:
		print(0)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline()

def RL():
	return map(int, sys.stdin.readline().split())

def RLL():
	return list(map(int, sys.stdin.readline().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))

def find(data, mi, ma, s):
	res.add(s)
	(a, b) = ([], [])
	p = mi + ma >> 1
	for v in data:
		if v <= p:
			a.append(v)
		else:
			b.append(v)
	if a and b:
		sa = sum(a)
		find(a, mi, max(a), sa)
		find(b, min(b), ma, s - sa)
for _ in range(N()):
	(n, m) = RL()
	a = RLL()
	key = 0
	for i in range(n - 1, -1, -1):
		if a[i] != i + 1:
			key = i + 1
			break
	if key == 0:
		for _ in range(m):
			input()
		print(1)
	else:
		s = 1
		for _ in range(m):
			o = input().split()
			i = int(o[0])
			p = float(o[1])
			if i >= key:
				s *= 1 - p
		print(1 - s)


import logging
import sys
from inspect import currentframe
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
logging.basicConfig(level=logging.DEBUG)

def dbg(*args):
	id2names = {id(v): k for (k, v) in currentframe().f_back.f_locals.items()}
	logging.debug(', '.join((id2names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args)))

def solve():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	exps = [tuple(map(float, input().split())) for _ in range(m)]
	exps.sort()
	limit_ri = 0
	for i in range(n - 1, -1, -1):
		if a[i] != i + 1:
			limit_ri = i
			break
	else:
		return 1
	unsort_prob = 1
	for (ri, pi) in exps:
		if ri > limit_ri:
			unsort_prob *= 1 - pi
	return 1 - unsort_prob

def main():
	t = int(input())
	for tt in range(t):
		print(solve())
main()


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	exp = []
	for i in range(m):
		x = input().split()
		exp.append([int(x[0]), float(x[1])])
	nm = -1
	for i in range(n, 0, -1):
		if a[i - 1] != i:
			nm = i
			break
	if nm == -1:
		print(1)
		continue
	total = 1
	for i in range(m):
		if exp[i][0] >= nm:
			total *= 1 - exp[i][1]
	print(1 - total)


import sys
input = sys.stdin.readline

def prog():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		a = list(map(int, input().split()))
		fail_prob = 1
		necessary_pre = 0
		for i in range(n - 1, -1, -1):
			if a[i] != i + 1:
				necessary_pre = i + 1
				break
		for i in range(m):
			(a, b) = input().split()
			a = int(a)
			b = float(b)
			if a >= necessary_pre:
				fail_prob *= 1 - b
		if necessary_pre == 0:
			print(1)
		else:
			print(1 - fail_prob)
prog()