#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 2e5+10;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;

int a[N];
int main() {
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    while(T--){
        int n, m;
        cin >> n >> m;
        for(int i = 1; i <= n; ++i)cin >> a[i];
        int f = 0;
        double ans = 1;
        for(int i = n; i >= 1; --i){
            if(a[i] != i){
                f = i;
                break;
            }
        }
        while(m--){
            int x;
            double fl;
            cin >> x >> fl;
            if(x >= f){
                ans *= 1-fl;
            }
        }
        if(f){
            cout << fixed << setprecision(6) << 1.0-ans << endl;
        }else{
            cout << 1.000000 << endl;
        }
    }
    return 0;
}
/**

*/
