// Arup Guha
// 4/27/2020
// Solution to 2020 FHSPS Problem: School Raffle

import java.util.*;

public class raffle {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Process all cases.
		for (int loop=0; loop<nC; loop++) {
		
			// Get basic input.
			int numItems = stdin.nextInt();
			int numBuy = stdin.nextInt();
			
			// Store all items here.
			item[] list = new item[numItems];
			
			// Read them in.
			for (int i=0; i<numItems; i++) {
				int value = stdin.nextInt();
				int numTickets = stdin.nextInt();
				list[i] = new item(value, numTickets);
			}
			
			// Sort in expected value order.
			Arrays.sort(list);
			
			// Result is just the sum of the expected values of the best items.
			double res = 0;
			for (int i=0; i<numBuy; i++)
				res += list[i].expectedValue();
		
			// Ta da!
			System.out.printf("%.2f\n", res);
		}
	}
}

class item implements Comparable<item> {

	public int value;
	public int numTickets;
	
	public item(int v, int nt) {
		value = v;
		numTickets = nt;
	}
	
	// The expected value of an item is v/(nt+1), so if this object has a higher ratio than
	// other, this function returns a negative integer, as desired, so it gets sorted first.
	public int compareTo(item other) {
		return other.value*(this.numTickets+1) - this.value*(other.numTickets+1);
	}
	
	// I can just do a double here; the rounding issue won't matter.
	public double expectedValue() {
		return 1.0*value/(numTickets+1);
	}
}