#include<bits/stdc++.h>
using namespace std;
int t,n,m,r,i,a[100008]= {1};
double p,q;
int main() {
    for(scanf("%d",&t); t--; printf("%lf\n",i?1-q:1),i=0) {
        for(scanf("%d%d",&n,&m); i++!=n; scanf("%d",a+i));
        for(q=1,--i; i==a[i]; --i);
        for(; m--; scanf("%d%lf",&r,&p),r<i?0.0:q*=1-p);
    }
    exit(0);
}