#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define len(a) a.size()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mp(x, y) make_pair((x), (y))
#define all(con) con.begin(),con.end()
#define sa(x) sort((x).begin(), (x).end())
#define show(x) cout<< #x <<" is "<< x <<"\n"

ll mod=1e9+7;

/* (x^y)%p */
ll po(ll x, ll y, ll p) 
{ 
    ll res = 1; 
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;  
        x = (x*x) % p; 
    } 
    return res; 
} 

void solve() {
    ll n,ki;
    cin>>n>>ki;
    double po=0,cu=1;
    ll A[n];
    for(int i=0;i<n;i++)
        cin>>A[i];
    ll k=n;
    while(A[k-1]==k and k>0)
        k--;
    for(int i=0;i<ki;i++) {
        ll z;
        double x;
        cin>>z>>x;
        if(z>=k) {
            po+=cu*x;
            cu*=(1-x);
            // cout<<cu<<endl;
        }
    }
    if(k==0)
        cout<<fixed<<setprecision(6)<<1.000000<<endl;
    else
        cout<<fixed<<setprecision(6)<<po<<endl;
}

int main() {
    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
    int t=1;
    cin>>t;
    while(t--) {
        solve();
    }
    return 0;
}
