#include <cstdio>
#include <queue>
#include <vector>
#include<iostream>
#include<map>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<bits/stdc++.h>

#define rep(i,a,b)  for(register  int i(a); i <= b; ++i)
#define ll long long
#define inf 1e15
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define PI acos(-1)
#define fi first
#define se second
#define pb push_back
#define debug(x)   printf("x=%d\n",x);
#define ls(x) arr[x].child[0]
#define rs(x) arr[x].child[1]
using namespace std;

const int N=1e6+10;
const ll mod=1e9+7;

inline ll read()
{
    ll X=0; bool flag=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
    while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
    if(flag) return X;
    return ~(X-1);
}


ll n,m,k;
int ar[N],lz[N];
ll ans;
vector<pair<int,double> >vt;
void solvve()
{
    n=read(); m=read(); vt.clear();
    rep(i,1,n)
    ar[i]=read();
    rep(i,1,m)
    {
        int k1=read(); double p; cin>>p;

        pair<int,double>t; t.fi=k1; t.se=p;
        vt.push_back(t);
    }
    sort(vt.begin(),vt.end()); reverse(vt.begin(),vt.end());
    int lst=n+1;
    for(int i=n;i>=1;i--)
    {
        if(ar[i]!=i) break;
        lst=i;
    }
    lst--;
    double ans=1.0;
    double tp=1.0;
    for(auto it:vt)
    {
        if(it.fi>=lst) tp*=(1.0-it.se);
    }
    ans-=tp;
    if(lst==0) ans=1.0;
    printf("%.10f\n",ans);
}
int main()
{
    // gbtb;
   //  freopen("input","r",stdin);

      //  while(scanf("%lld",&n)!=EOF)

       int T;T=read();while(T--)
    {
        //printf("cas=%d   ",++cc);
        solvve();
    }
    return 0;

}
