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

#define endl '\n'
#define int long long

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int tests; cin >> tests;
	while(tests --> 0) {
		int n, m; cin >> n >> m;
		vector< int > vec(n);
		for(int &i : vec) cin >> i;
		int last = n;
		while(last > 0 and vec[last - 1] == last) last --;
		double pof = (last == 0 ? 0 : 1);
		for(int i = 0; i < m; i ++) {
			int r; cin >> r;
			double p; cin >> p;
			if(r >= last) {
				pof *= (1 - p);
			}
		}
		cout << fixed << setprecision(6) << 1 - pof << endl;
	}

	return 0;
}