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

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;

#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ALL(a,n) a,a+n
#define ALLV(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=int(b); ++i)
#define rFOR(i,a,b) for(int i=a; i>=int(b); --i)

typedef long long ll;
typedef pair<int,int> pii;

const int maxN = 100005;
const int INF = (int)2e9;

int T, N, M, A[maxN];
double P[maxN];

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin >> T;
    REP(_, T){
        cin >> N >> M;
        FOR(i, 1, N){
            cin >> A[i];
            P[i] = 0;
        }
        FOR(i, 1, M){
            int r;
            double p;
            cin >> r >> p;
            P[r] += p - p*P[r];
        }
        double ans = 0;
        rFOR(i, N, 1){
            if(i==1) ans = 1;
            if(i==A[i]) continue;
            double p = 1;
            rFOR(j, N, i){
                ans += P[j]*p;
                p *= 1.0-P[j];
            }
            break;
        }
        printf("%.6f\n", ans);
    }
    return 0;
}