#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const ll NN = 1e5 + 5;
const ll mo = 1e9 + 7;
ll t, n, m;
ll a[NN];
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> t;
	while(t--)
	{
		cin >> n >> m;
		for(ll i = 1; i <= n; i++)
			cin >> a[i];
		ll bts = -1;
		for(ll i = n; i >= 1; i--)
		{
			if(a[i] != i)
			{
				bts = i;
				break;
			}
		}
		long double has = 1;
		while(m--)
		{
			ll r;
			long double d;
			cin >> r >> d;
			if(r >= bts)
			{
				has *= (1.0 - d);
				// cout << (1.0 - d) << "\n";
			}
		}
		// cout << has << "\n";
		has = 1.0 - has;
		if(bts == -1)
			has = 1.0;
		cout << fixed << setprecision(6) << has << "\n";
	}
}