#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    int t,n,m,i;
    cin>>t;
    for(i=1;i<=t;i=i+1)
    {
        cin>>n>>m;
        int a[n],j,r[m],u=0,q=0;
        double p[m],e,f,c,sum=1.0,h,l;
        for(j=0;j<n;j=j+1)
        {
            cin>>a[j];
            if(a[j]!=j+1)
            {
                q=j+1;
            }
        }
        for(j=0;j<m;j=j+1)
        {
            cin>>r[j];
            cin>>p[j];
            if(r[j]>=q && q!=0)
            {
                if(u==0)
                {
                    u=1;
                    e=p[j];
                    f=1.0-e;
                }
                c=p[j];
                h=1.000000-c;
                sum=sum*h;
                //printf("%lf %lf %lf ",f,e,sum);
            }
        }
        if(q==0)
        {
            printf("1.000000\n");
        }
        else if(u==0)
        {
            printf("0.000000\n");
        }
        else
        {
        l=e+(f-sum);
        printf("%lf\n",l);
        }
    }
}
