#include<bits/stdc++.h>
#define f1(a,b)   for( long long int i= a; i<=b; i++)
#define f2(a,b)   for( long long int i= a; i<b; i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define ll long long int
#define MOD 1000000007
class Pair{
public:
    ll x;
    double y;
    Pair(ll x,double y)
     : x(x), y(y)
      {
    }
};
bool cmp(Pair a,Pair b)
{
    return a.x<b.x;
}
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
ll n, minlen,m,t,k,x,d1,d2,v1,v2,y;
double prob,ans;
cin>>t;
f1(1,t){
cin>>n>>m;
ll ar[n+1],ck=0;
minlen=-1;
f1(1,n)
{
    cin>>ar[i];
    if(ar[i]!=i)
        minlen=i;
}
vector<pair<ll,double>>v;
f2(0,m)
{
    cin>>k>>prob;
    v.PB(MP(k,prob));
}
sort(v.begin(),v.end());
//f2(0,m)
//{
//    cout<<v[i].F<<" "<<v[i].S<<endl;
//}
cout<<fixed<<setprecision(6);
if(minlen==-1)
    ans=1;
else{


        ans=1;
        f2(0,m)
        {
            if(v[i].F>=minlen){
                    if(v[i].S==1)
                        ans=1;
            else
            ans=ans*(1.0-v[i].S);}
        }
        ans=1-ans;
         ll a=v[m-1].F;
    f1(a+1,n)
    {
        if(ar[i]!=i)
        { ans=0;
        break;}
    }
}
   cout<<ans<<endl;
}
    return 0;
}













