#include <iostream>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
int a[N];

void solve()
{
    int n,m;
    cin >> n >> m;
    a[0] = 2e9;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    while(a[n] == n)
        n--;
    double ans = 1.0;
    for(int i=1;i<=m;i++)
    {
        int r;
        double q;
        cin >> r >> q;
        if(r >= n)
            ans = ans * (1.0-q);
    }
    if(n == 0)
        ans = 0;
    printf("%0.6lf\n",1.0-ans);
}
int main( )
{
    int T;
    cin >> T;
    while(T--)
    {
        solve();
    }
    return 0;
}