#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
#define I_love_andrey_sandimirov cout.precision(20); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define forn(i, n) for(ll (i) = 0; (i) < (n); ++(i))
#define fornm(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define rfornm(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define readvec(vector, n) {ll temp_vec_val;forn(inc, n){cin >> temp_vec_val;vector.push_back(temp_vec_val);}}
#define printvec(vector, delimeter) {ll length_of_vector=vector.size();\
                                    forn(elementvec, length_of_vector){cout << vector[elementvec] << delimeter;}}
#define all(vector) (vector).begin(), (vector).end()
#define rall(vector) (vector).rbegin(), (vector).rend()
#define endl "\n"
#define sz(something) (ll)something.size()
const ld EPS = 1e-8;
const ll MOD = 1000000007;
const ll INF = 1e18;
const ld pi = 2.0*acos(0.0);
ll n, m, k, p, q, t, sum = 0, cnt = 0;
ll mx = -INF;
ll mn = INF;
bool flag = 0;
vll v;
string s = "", s1, s2;
char c;

void solve()
{
    cin >> t;
    while(t--)
    {
        cin >> n >> m;
        v.clear();
        readvec(v,n);
        vector<pair<ll,ld>> vv;
        forn(i,m)
        {
            ld q;
            cin >> p >> q;
            vv.pb({p,q});
        }
        sort(rall(vv));
        p = n-1;
        while(p>=0&&v[p]==p+1)--p;
        if(p==-1)
        {
            cout << 1 << endl;
            continue;
        }
        ld cn=1.;
        forn(i,m)
        {
            if(vv[i].first<=p) break;
            cn*=1.-vv[i].second;
        }
        cout << fixed << setprecision(10) << 1.0-cn << endl;
    }
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("H:\\repos\\projects\\contests_vsc\\in.txt", "r", stdin);
    freopen("H:\\repos\\projects\\contests_vsc\\out.txt", "w", stdout);
#endif
    I_love_andrey_sandimirov
    solve();
    return 0;
}