//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
void debug3(int *t,int st,int n) {cerr << '{' << t[st];for(int i=st+1;i<=n;i++) cerr<<",",__print(t[i]);cerr <<"}"<<'\n';}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#define debug2(x...) cerr<<"[" << #x << "] = "; debug3(x)
#endif

#define N 200005
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define sf second.first
#define ss second.second
#define INF 1e9

int v[N];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("test.in", "r", stdin);
    int t,n,m,i,j,x;
    double pr,pb,sol;

    cin >> t ;
    while ( t-- )
    {
        pr = 1 ;
        sol = 0 ;
        cin >> n >> m ;
        for ( i = 1; i <= n ; i++ )
            cin >> v[i] ;
        for ( j=n ; v[j]==j&&j; j-- ) ;
        while ( m-- )
        {
            cin >> x >> pb ;
            if ( x < j )
                continue ;
            sol = sol + pr*pb ;
            pr = pr*(1-pb) ;
        }
        if ( j == 0 )
            sol = 1 ;
        cout << sol << '\n';
    }
}
