// Arup Guha
// 8/14/2017
// Solution to UCF Locals Problem: Videogame Probability

import java.util.*;

public class game {

	public static ArrayList<Double> prob;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Process cases.
		for (int loop=0; loop<numCases; loop++) {

			// I store the data uncompressed, with the probability of each item.
			int n = stdin.nextInt();
			prob = new ArrayList<Double>();
			for (int i=0; i<n; i++) {
				int need = stdin.nextInt();
				double p = stdin.nextDouble();
				for (int j=0; j<need; j++) prob.add(p);
			}

			int tot = prob.size();
			int numAtt = stdin.nextInt();

			// Initialize stuff - dp[i][j] is the probability of having j successes in i attempts.
			double[][] dp = new double[numAtt+1][tot+1];
			dp[0][0] = 1;

			// go through dp state.
			for (int i=1; i<dp.length; i++) {
				for (int j=0; j<dp[i].length; j++) {

					// Calculate the probability of getting to state (i,j) with a miss and a hit.
					double missTerm = j < tot ? dp[i-1][j]*(1-prob.get(j)) : dp[i-1][j];
					double makeTerm = j > 0 ? dp[i-1][j-1]*prob.get(j-1) : 0;

					// This is our probability for this state.
					dp[i][j] += (missTerm+makeTerm);
				}
			}

			// Ta da!
			System.out.printf("%.3f\n", dp[numAtt][tot]);
		}
	}
}