/*
Author : Vidish Joshi
*/

#include <bits/stdc++.h>
using namespace std;

//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#define ll long long int
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
#define FOR1(i, m, n) for(i=m; i<n; i++)
#define FOR2(i, n, m) for(i=n-1; i>=m; i--)
#define re(v) ll v; cin>>v
#define mod 1000000007
#define mod2 998244353
#define mp make_pair
#define pb push_back
#define fill(a) memset(a, 0, sizeof(a))
#define start ll t; cin>>t; while(t--)
#define start1 ll t = 1; while(t--)
#define F first
#define S second
#define br "\n"

void solve(){	
	int n, m; cin>>n>>m;
	int a[n], b[n];
	for(int i=0; i<n; i++) cin>>a[i], b[i] = a[i];
	
	int place = -1;
	sort(b, b+n);
	for(int i=n-1; i>=0; --i){
		if(a[i]!=b[i]){
			place = i;
			break;
		}
	}
//	cout<<place<<" bif\n";
	vector<pair<int, double> > v;
	int x; double y;
	
	for(int i=0; i<m; i++){
		cin>>x>>y;
		x--;
		if(x >= place){
			v.pb({x, y});
		}
	}
//	cout<<v.size()<<" ll\n";
	double last = 1;
	double ans = 0;
	for(int i=0; i<v.size(); i++){
		ans += (v[i].S * last);
		last *= ((double(1)) - v[i].S);
	}
	
	if(place == -1){
		cout<<"1.000000000\n";
		return;
	}
	
	cout<<fixed<<setprecision(9)<<ans<<br;
}

int main(){
    FIO;
    start{
        solve();
    }
    return 0;
}
