#include <bits/stdc++.h>
using namespace std;
#define mod1  1000000007
#define mod2  998244353
#define ff   first
#define ss   second
#define int  long long
#define ll   unsigned long long
#define pb   push_back
#define mp   make_pair
#define pii  pair<int,int>
#define inf  9e18
#define N    15000005
#define pi   2*asin(1.0)
#define endl "\n"
 
void fast() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}



int32_t main() {
    fast();
    int t; cin>>t;
    while(t--){
        int n,m; cin>>n>>m;
        int arr[n];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        int cnt=n;
        int len=0;
        for(int i=n-1;i>=0;i--){
            if(arr[i]==cnt){
                cnt--;
            }
            else{
                len=i+1; break;
            }
        }
        double ans=1.0;
        for(int i=0;i<m;i++){
            int r; double p;
            cin>>r>>p;
            if(r>=len){
                ans=(ans*(1.0-p));
            }
        }
        ans=1.0-ans;
        if(len==0) ans=1.0;
        cout<<fixed<<setprecision(6)<<ans<<endl;
    }
    return 0;
}
