#include<bits/stdc++.h>

using namespace std;

#define For(i, a, b) for(int i = a; i <= b; ++ i)
#define ii pair<int, int>
#define fi first
#define se second

const int N = 3e5 + 1;

int t, n, m;
int a[N];

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> t;
    while(t--){
        cin >> n >> m;
        For(i, 1, n) cin >> a[i];

        double res = 1, p, ans = 0; int  lim = 0, r;

        for(int i = n; i > 0; -- i)
            if(a[i] != i){ lim = i; break; }
        For(i, 1, m){
            cin >> r >> p;
            if(r >= lim){
                ans += res * p;
                res *= (1.0 - p);
            }
        }
        if(lim == 0) ans += res;
        cout << setprecision(6) << fixed << ans << endl;
    }
}
