// Arup Guha
// 4/8/2020
// Solution to COP 4516 Team Final Exam Question: Scavenger Hunt

import java.util.*;

public class scavenger {

	public static int n;
	public static ArrayList[] g;
	public static double[] memo;
	public static int[] bonus;

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Process each case.
		for (int loop=0; loop<nC; loop++) {
		
			n = stdin.nextInt();
			bonus = new int[n];
			Arrays.fill(bonus, 1);
			
			// Update non-one bonuses.
			int numB = stdin.nextInt();
			for (int i=0; i<numB; i++) {
				int idx = stdin.nextInt()-1;
				int mult = stdin.nextInt();
				bonus[idx] = mult;
			}
			
			// Form graph.
			g = new ArrayList[n];
			for (int i=0; i<n; i++)
				g[i] = new ArrayList<Integer>();
			
			// Go through each vertex, form graph.
			for (int i=0; i<n; i++) {
				int next = stdin.nextInt();
				for (int j=0; j<next; j++)
					g[i].add(stdin.nextInt()-1);
			}
		
			// Set up memo.
			memo = new double[n];
			Arrays.fill(memo, -1);
			
			// Ta da!
			System.out.printf("%.2f\n",go(0));
		}
	}
	
	public static double go(int v) {
	
		// Did this before.
		if (memo[v] > -.5) return memo[v];
		
		// End of hunt.
		if (g[v].size() == 0) return bonus[v];
		
		// Try each path.
		double total = 0;
		for (int i=0; i<g[v].size(); i++) {
		
			// Expected score for this path.
			double tmp = go((Integer)g[v].get(i));
			total += bonus[v]*(1 + tmp);
		}
		
		// Store and return.
		return memo[v] = total/g[v].size();
	}
}