#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define vll vector<ll>
using namespace std;
inline void sol() {
  ll n, m;
  cin >> n >> m;
  vll a(n);
  for(ll i=0;i<n;i++){
    cin >> a[i];
  }
  vector<pair<int,double>> b(m);
  for(int i=0;i<m;i++){
    int r; double p;
    cin >> r >> p;
    b[i] = {r, p};
  }
  int rm;
  for(rm = n-1; rm >= 0 and a[rm] == rm + 1; rm--);
  if(rm == -1){
    cout << "1\n";
    return;
  }
  double ans = 1;
  for(int i=0;i<m;i++){
    if(b[i].first - 1 >= rm)
      ans *= (1 - b[i].second);
  }
  // cout << 1 - ans << endl;
  printf("%0.6lf\n", 1 - ans);
}
int main() {
  // cin.tie(0);
  // ios_base::sync_with_stdio(false);

  int t;
  cin >> t;
  while(t--)
    sol();

  return 0;
}