#include <bits/stdc++.h>

#define ALL(x) x.begin(), x.end()
#define pb push_back
#define db1(x) cout << #x << " = " << x << endl
#define db2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
using namespace std;
void localFileInput() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}
typedef long long ll;
typedef pair<int, int> pii;
const ll mod = 1e9+7;
const int N = 1e5+10;
int n, m, a[N];
struct Node
{
    int r;
    double p;
    void input() {
        scanf("%d%lf", &r, &p);
    }
}b[N];
int r[N];
bool cmp(Node a , Node b) {
    return a.r < b.r;
}
void sol() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++ i) scanf("%d", &a[i]);
    for (int i = 1; i <= m; ++ i) b[i].input();
    sort(b + 1, b + 1 + m, cmp);
    for (int i = 1; i <= m; ++ i) r[i] = b[i].r;
    int id = 0;
    for (int i = n; i >= 1; -- i) if(a[i] != i) {
        id = i;
        break;
    }
    if(id == 0) {
        puts("1.000000");
        return ;
    }
    int st = lower_bound(r+1, r+1+m, id) - r;

    double ans = 1.0;
    for (int i = st; i <= m; ++ i) 
        ans = ans * (1 - b[i].p);
    printf("%.6f\n", 1-ans);
}
int main() {
    localFileInput();
    int _; scanf("%d", &_); while(_ --) sol();
    return 0;
}