#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
ll t,n,m,x,ed;
double ans,y;
int main() {
	scanf("%lld",&t);
	while (t--) {
		scanf("%lld%lld",&n,&m);
		ans=1; ed=0;
		for (int i=1;i<=n;i++) {
			scanf("%lld",&x);
			if (x!=i) ed=i;
		}
		while (m--) {
			scanf("%lld%lf",&x,&y);
			if (x>=ed)
				ans=ans*(1-y);
		}
		if (ed==0) ans=0;
		printf("%.6lf\n",1-ans);
	}
	return 0;
}