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

typedef long long int ll;

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    int t; cin >> t;
    while (t--)
    {
        int n, m; cin >> n >> m;
        vector<int> arr(n);
        for(int &x : arr) cin >> x;

        int last = n-1;
        int nxt = n;
        while(last >= 0 && arr[last] == nxt)
            last --, nxt--;

        last ++;
        double ans = (last == 0 ? 1 : 0);
        while(m--) {
            int r; double p;
            cin >> r >> p;
            if(r >= last) {
                ans = ans + p - ans*p;
            }
        }

        cout << fixed << setprecision(6) << ans << "\n";
    }
    
    
    cerr << "Run time: " << fixed << setprecision(3) << (double)clock() / CLOCKS_PER_SEC << "s" << endl;
    return 0;
}