#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;

#define pb push_back




int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int t;
    cin >> t;

    while (t--) {
        int n, m;
        cin >> n >> m;

        cout << fixed << setprecision(10);
        vector<int> a(n+1);
        int mx = 0;
        for (int i=1; i<=n; i++) {
            cin >> a[i];
            if (a[i] != i) mx = i;
        }

        vector<int> r(m);
        vector<double> p(m);
        for (int i=0; i<m; i++) cin >> r[i] >> p[i];

        if (mx == 0) cout << 1.0 << endl;
        else {
            double cur = 0;

            for (int i=m-1; i>=0; i--) {
                if (r[i] >= mx) {
                    cur = p[i] + (1-p[i])*cur;

                }
            }
            cout << cur << endl;
        }
    }
    
    
    
    return 0;
}
