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

int main (void) {
    int t;
    cin >> t;
    while(t--) {
        int n, m;
        double ans = 1;
        cin >> n >> m;
        int a[n];
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        int sign=0;
        for (int i = n-1; i >= 0; i--) {
            if(a[i] != i+1) {
                sign = i;
                break;
            }
        }
        for (int i = 0; i < m; i++) {
            int l;
            double p;
            cin >> l >> p;
            if(l >= sign+1)
                ans *= (1 - p);
        }
        ans = 1 - ans;
        if(sign)
            cout << fixed << setprecision(7) << ans << endl;
        else
            cout << "1.0000000" << endl;
    }
}