#include<iostream>
using namespace std;
int main()
{int t;int n,mn,i,flag;int a[100000];double m[100000][2];double p;
cin>>t;
while(t--)
{cin>>n>>mn;flag=0;p=0;
i=0;
while(i<n)
{cin>>a[i];i++;
}
i=i-1;
while(i>=0)
{
    if(a[i]!=i+1)
    {flag=i;
    break;}
    i--;
}
i=0;
while(i<mn)
{cin>>m[i][0]>>m[i][1];i++;
}
if (flag==0) p=1;
else
{i=0;
while(i<mn)
{if(m[i][0]>flag)
{p=p+m[i][1]*(1-p);
}i++;
}
    
}
cout<<p<<endl;
}

}