1.
package acm_11816_hst;
import java.util.HashMap;
import java.util.Scanner;
/**
* FWP, Ausgew¦hlte Probleme aus dem ACM Programming Contest, SS10
* Problem: acm_11816_hst
* Link:
*
* @author Martin Lambeck
* @version 1.0, 10.09.2010
*
* Method : adhoc
* Status : Accepted
* Runtime: 2.460
*/
public class Main
{
static Scanner sc = new Scanner(System.in);
public static void main(String... args)
{
int cases = sc.nextInt();
for (int i = 0; i < cases; i++)
testcase();
}
public static void testcase()
{
HashMap<String, long[]> hm = new HashMap<String, long[]>();
int n = sc.nextInt();
int m = sc.nextInt();
sc.nextLine();
for (int i = 0; i <n; i++)
{
String[] line = sc.nextLine().split(" ");
String cat = line[0];
long pst = (long) (Double.parseDouble(line[1].substring(0, line[1].length()-1)) * 100 + 0.001);
long gst = (long) (Double.parseDouble(line[2].substring(0, line[2].length()-1)) * 100 + 0.001);
long hst = (long) (Double.parseDouble(line[3].substring(0, line[3].length()-1)) * 100 + 0.001);
hm.put(cat, new long[]{pst, gst, hst});
}
long sum = 0;
for (int i = 0; i < m; i++)
{
String[] line = sc.nextLine().split(" ");
String cat = line[0];
long price = (long) (Double.parseDouble(line[1].substring(1, line[1].length())) * 100 + 0.001);
long pst = price * hm.get(cat)[0] / 1000;
long gst = price * hm.get(cat)[1] / 1000;
long hst = price * hm.get(cat)[2] / 1000;
pst = pst / 10 + (pst % 10 >= 5 ? 1 : 0);
gst = gst / 10 + (gst % 10 >= 5 ? 1 : 0);
hst = hst / 10 + (hst % 10 >= 5 ? 1 : 0);
sum += (hst - gst - pst);
}
boolean neg = sum < 0;
sum = Math.abs(sum);
System.out.printf("%s%d.%02d%n", (neg ? "-" : ""), sum / 100, sum % 100);
}
}