#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e6+10;
int a[N];
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		int n,m;
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
		double ans=0,prep=1;
		int pre=n+1;
		for(int i=n;i>=1;i--){
			if(a[i]==i)pre=i;
			else break;
		}
		if(pre==1)ans=1,prep=0;
		for(int i=1;i<=m;i++){
			int x;double p;
			scanf("%d%lf",&x,&p);
			if(x>=pre-1){
				ans+=p*prep;
				prep=prep*(1-p);
			} 
		}
		printf("%.6lf\n",ans);
	}
}