/*
	Solution by:- 
	--------------Sannidhay Vashal
	----------------NIT SRINAGAR
 
*/
#include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<math.h>
#include<climits>
#include<set>
#include<cstring>
#include<unordered_map>
#include <cstdlib> 
#include<cmath>
#include<string>
#include<iomanip>
 
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll            long long int
#define ull           unsigned long long int
#define cinll(x)      ll x;cin>>x;
#define cini(x)       int x;cin>>x;
#define cins(x)       string x;cin>>x;
#define vect(x)       vector<ll> x;
#define vect1(x)      vector<ll> x;x.push_back(0);
#define pb(x)         push_back(x)
#define mp(x,y)       make_pair(x,y)
#define MAX           1e18
#define MIN           -1000000007
#define MOD           1000000007

using namespace std;

struct custom_compare1{
  bool operator()(pair<ll,ll> a,pair<ll,ll> b){
    if(a.second==b.second){
      return a.first>b.first;
    }
    return a.second<b.second;
  }
};
struct custom_compare2{
  bool operator()(pair<ll,ll> a,pair<ll,ll> b){
    return a.first>b.first;
  }
};

int main(){
  fio;
  cinll(t);
  while(t--){
    cinll(n);cinll(m);
    vector<ll> arr;
    ll pos = n+1;
    for(ll i=0;i<n;i++){
      cinll(x);
      arr.pb(x);
    }
    for(ll i=n-1;i>=0;i--){
      if(i+1==arr[i]){
        pos = i+1;
      }else{
        break;
      }
    }
    pos--;
    long double val = 1;
    while(m>0){
      cinll(ind);
      double p;cin>>p;
      if(ind>=pos){
        val *= (1-p);
      }
      m--;
    }
    if(pos==0)  cout<<setprecision(6)<<fixed<<1.00<<"\n";
    else  cout<<setprecision(6)<<fixed<<1-val<<"\n";
  }
  return 0;
}
