Problem: Ron is a happy owner of a permutation a of length n.

A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).

<image>

Ron's permutation is subjected to m experiments of the following type: (r_i, p_i). This means that elements in range [1, r_i] (in other words, the prefix of length r_i) have to be sorted in ascending order with the probability of p_i. All experiments are performed in the same order in which they are specified in the input data.

As an example, let's take a look at a permutation [4, 2, 1, 5, 3] and an experiment (3, 0.6). After such an experiment with the probability of 60\% the permutation will assume the form [1, 2, 4, 5, 3] and with a 40\% probability it will remain unchanged.

You have to determine the probability of the permutation becoming completely sorted in ascending order after m experiments.

Input

Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 100).

The first line of each test case contains two integers n and m (1 ≤ n, m ≤ 10^5) — the length of the permutation and the number of experiments, respectively.

The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ n) — contents of the permutation.

The following m lines of each test case each contain an integer r_i and a real number p_i (1 ≤ r_i ≤ n, 0 ≤ p_i ≤ 1) — the length of the prefix and the probability of it being sorted. All probabilities are given with at most 6 decimal places.

It is guaranteed that the sum of n and the sum of m does not exceed 10^5 (∑ n, ∑ m ≤ 10^5).

Output

For each test case, print a single number — the probability that after all experiments the permutation becomes sorted in ascending order. Your answer will be considered correct if its absolute or relative error does not exceed 10^{-6}.

Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} ≤ 10^{-6}.

Example

Input


4
4 3
4 3 2 1
1 0.3
3 1
4 0.6
5 3
4 2 1 3 5
3 0.8
4 0.6
5 0.3
6 5
1 3 2 4 5 6
4 0.9
5 0.3
2 0.4
6 0.7
3 0.5
4 2
1 2 3 4
2 0.5
4 0.1


Output


0.600000
0.720000
0.989500
1.000000

Note

Explanation of the first test case: It can be demonstrated that whether the final permutation is sorted or not depends solely on sorting being performed in the (4, 0.6) experiment.

Solution (in JAVA):

Solution:



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.sql.SQLOutput;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Stack;
import java.util.*;

public class javacp {
    static final InputStreamReader it = new InputStreamReader(System.in);
    static final BufferedReader br = new BufferedReader(it);

    static int sti(String s)
    {
        return Integer.parseInt(s);
    }
    static long stl(String s)
    {
        return Long.parseLong(s);
    }
    static double std(String s){return Double.parseDouble(s);}

    static int[] sta(String[] s)
    {
        int[] b = new int[s.length];
        for(int i=0;i<s.length;i++)
        {
            b[i] = sti(s[i]);
        }
        return b;
    }

    static double[] staDouble(String[] s){
        double[] b = new double[s.length];
        for(int i = 0 ;i < s.length ;i++){
            b[i] = std(s[i]);
        }
        return b;
    }

    static int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    static long nCr(int n, int r)
    {
        return fact(n) / (fact(r) *
                fact(n - r));
    }

    // Returns factorial of n
    static long fact(int n)
    {
        long res = 1;
        for (int i = 2; i <= n; i++)
            res = res * i;
        return res;
    }

    static int inputint () throws IOException{
        return sti(br.readLine());
    }

    static long inputlong () throws IOException{
        return stl(br.readLine());
    }
    static int[] inputarr () throws IOException{
        return sta(br.readLine().split(" "));
    }

    static double[] inputarrDouble() throws IOException{
        return staDouble(br.readLine().split(" "));
    }

    public static void main(String[] args) throws IOException {

        // t-> no of test cases
        // taking input testcase
        int t = inputint();
        while(t-->0){
            String[] l1 = br.readLine().split(" ");
            int[] line1  = new int[l1.length];
            for(int i=0 ;i < l1.length ;i++){
                line1[i] = Integer.parseInt(l1[i]);
            }

            int n = line1[0];
            int m = line1[1];

            String[] s = br.readLine().split(" ");
            int arr[] = new int[s.length];
            for (int i = 0 ; i < s.length ; i++){
                arr[i] =  Integer.parseInt(s[i]);
            }
            //Here we have to find out K from last upto where our array is already sorted!
            int k = 0;
            for(k = n-1 ; k >= 0 ; k--){
                if(arr[k] != k+1){
                    break;
                }
            }
            k  = k+1;

            double[] index = new double[m];
            double[] prob = new double[m];

            for (int i = 0 ; i < m ;i++){
                double[] indexprob = inputarrDouble();
                index[i] = indexprob[0];
                prob[i] = indexprob[1];
            }

            if(k==0){
                System.out.println("1.000000");
                continue;
            }

            double ct = 1;
            double pb = 0;

            for(int i =0 ; i < m ;i++){
                if(index[i]>=k){
                    pb += ct*prob[i];
                    ct = ct*(1-prob[i]);
                }
            }
            System.out.format("%.6f", pb);
            System.out.println();
        }

    }
    static long maxSubArraySum(int a[])
    {
        int size = a.length;
        long max_so_far = Long.MIN_VALUE, max_ending_here = 0;

        for (int i = 0; i < size; i++)
        {
            max_ending_here = max_ending_here + a[i];
            if (max_so_far < max_ending_here)
                max_so_far = max_ending_here;
            if (max_ending_here < 0)
                max_ending_here = 0;
        }
        return max_so_far;
    }

    static void printArrayList(ArrayList<Integer> a)
    {
        for(int i=a.size()-1;i>=0;i--)
        {
            System.out.print(a.get(i)+" ");
        }
    }
    static void maximumInAWindow(int[] a , int k){

        Deque<Integer> dq = new ArrayDeque<>(k);
        dq.addFirst(0);
        //for first K elements

        for(int i=1;i<k;i++)
        {
            while(a[dq.peekLast()] < a[i])
            {
                dq.removeLast();
                if(dq.size()==0)
                    break;
            }
            dq.addLast(i);
        }

        System.out.print(a[dq.peekFirst()]+" ");


        //For rest of the elements

        for(int i = 1 ; i < a.length - k +1 ; i++){

            while(dq.peekFirst() < i) {
                dq.removeFirst();
                if(dq.size()==0)
                    break;
            }

            if(dq.size()>0)
            {
                while(a[dq.peekLast()] < a[i+k-1])
                {
                    dq.removeLast();
                    if(dq.size()==0)
                        break;
                }
            }

            dq.addLast(i+k-1);
            System.out.print(a[dq.peekFirst()]+" ");
        }
    }
}