/*
ID: Trump
TASK: 
LANG: C++
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include <iostream>
#include <fstream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double lb;
typedef double db;
typedef int it;
//#define MARK
const ll losn=1e6+5;
const ll maxn=1e5+5;
const ll minn=1e3+5;
const ll tiny=1e2+5;
const ll inf=1e9;
const ll binf=1e18;
const ll mod=1e9+7;
const ll hmod=4698571;
const lb pi=3.1415926;
const ll myn=0;
void gk(){cout<<"---------------"<<endl;}
void ck(){cout<<1<<endl;}
void ck(ll a){cout<<a<<endl;}
void ck(ll a[minn][minn],ll n,ll m){for(ll i=1;i<=n;i++){for(ll j=1;j<=m;j++){cout<<a[i][j]<<" ";}cout<<endl;}}
ll n,m,k,T,u,v,len;

lb arr[maxn];
lb a[maxn],b[maxn];
int main(){
//#ifdef MARK
//    freopen("input.in", "r", stdin);
//    freopen("ouput.out", "w", stdout);
//    freopen("input.in", "r", stdin);
//    freopen("ouput.out", "w", stdout);
//#endif
	ll t;
	cin>>t;
	while(t--){
		cin>>n>>m;
		for(ll i=1;i<=n;i++){
			cin>>arr[i];
		}
		/*
		0 10
		6 4
		7.2
		*/
		lb ld=n;
		for(lb i=n;i>=1;i--){
			if(arr[(ll)i]==i){
				ld--;
			}else{
				break;
			}
		}
		for(ll i=1;i<=m;i++){
			cin>>a[i]>>b[i];
		}
		lb le=0,re=10;
		if(ld==0){
			le=10;
			re=0;
		}
		for(ll i=1;i<=m;i++){
			if(a[i]>=ld){
				lb left=re*b[i];
				le+=left;
				re-=left;
			}
		}
		printf("%.6Lf\n",le/(10*1.0));
	}
	return 0;
}
/*
0 10
0 10
4 6


2
5 3
4 2 1 3 5
3 0.8
4 0.6
5 0.3
*/