//Lets Begin With Name Of Lord Mahadev..
#include<bits/stdc++.h>
#define mod 1000000007
#define pi 3.1415926535
#define ll long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define cy cout<<"YES"<<endl;
#define cn cout<<"NO"<<endl;
#define pb(v) push_back(v);
const int MaxN=1e5+5;
using namespace std;

ll t,n,m,k,r,a[MaxN];
ll alreadysorted[MaxN],willbesorted[MaxN],sortedtillhere[MaxN];
string s;

int main(){
    fast;
    cin>>t;

    while(t--){
        cin>>n>>m;

        for(int i=0;i<n;i++){
            cin>>a[i];
            if(i == 0){
                alreadysorted[i]=1;
                sortedtillhere[i]=1;
            }else{
                if(alreadysorted[i-1] && a[i] > a[i-1]){
                    alreadysorted[i] = 1;
                }else{
                    alreadysorted[i] = 0;
                }
            }
            willbesorted[i]=0;
        }
        ll x=n;
        willbesorted[n]=1;
        for(int i=n-1;i>=0;i--){
            if(a[i] == x){
                willbesorted[i]=1;
            }else{
                break;
            }
            x--;
        }
//        for(int i=0;i<n;i++){
//            cout<<alreadysorted[i]<<" "<<willbesorted[i]<<endl;
//        }
        double ans1=0,ans2=0,ans,p;
        for(int i=0;i<m;i++){
            cin>>r>>p;
            r--;
            if(alreadysorted[r]){
                //cout<<"skipped"<<endl;
                continue;
            }
            if(willbesorted[r+1]){
//                ans1=(ans1+ans2)*p;
//                ans2=ans2*(1.0-p);
//                if(ans1 == 0){
//                    ans1=p;
//                }
//                if(ans2 == 0){
//                    ans2=1.0-p;
//                }
                ans1=ans1+ans2*p;

                ans2=ans2*(1-p);
                if(ans1 == 0){
                    ans1=p;
                }
                if(ans2 == 0){
                    ans2=1.0-p;
                }
                ans=ans1;
                //cout<<ans1<<" "<<ans2<<endl;
            }else{

            }
        }
        if(alreadysorted[n-1] || ans1>1.0){
            ans1=1;
        }
        cout<<fixed<<setprecision(10)<<ans1<<endl;
    }
    return 0;
}







