Coffee

Interview

Time limit1sMemory limit512 MB

Summary
For each person, add the price of their ordered coffee size to a shared delivery fee of floor(100/P), then snap the total to a multiple of 5 only when it is 1 off.
Level

Easy3 of 10

Topics
Hash map, Implementation, Math, Simulation
Solved
No attempts yet

Problem

Given the prices of different types of coffee (latte, cappuccino, ...) for each size (small, medium, and large), and a list of orders of a group of persons. Your task is to find how much each person will pay eventually. The cost that a person needs to pay is the cost of coffee he/she ordered in addition to the delivery fees. The delivery fees for each person are 100$ divided by the number of persons (rounded down).

The final cost ignores a difference of 1$ greater or less than what should be paid, to the nearest multiple of 5 (i.e. 44$ and 46$ will be rounded to 45$. However, 47$ and 48$ will not be changed).

Input

The first line of the input contains a single integer T specifying the number of test cases.

Each test case begins with a line containing two integers C and P (1 ≤ C, P ≤ 100), in which C is the number of different types of coffees, and P is the number of unique persons.

Then C lines follow, giving the coffee types. Each line contains a string N and three integers S, M, and L (1 ≤ S, M, L ≤ 100), in which N is a coffee name, S, M, and L are the prices for small, medium, and large sizes, respectively. Each coffee type will appear exactly once per test case.

Then P lines follow, giving the list of orders. Each line contains three strings X, Y, and Z, in which X is a person name, Y is the coffee size (Y ∈ {small, medium, large}), and Z is a coffee name. It is guaranteed that all the given P names are distinct, and each person will order coffee type that exists.

Both the coffee and person names are non-empty strings consisting of lowercase and uppercase English letters with a length of no more than 15 letters.

Output

For each test case, print P lines in which each line contains two space-separated values, the name of the person and the total cost he/she will pay for his/her order. Print the persons in the same order as given in the input.

Hint

The delivery fees is 100$ and divided by 3 persons, so each of them will pay ⌊100/3⌋ = 33$.

  • The cost for "Mohammed" is 34$ for drinks, 33$ for delivery fees, this will be 67$, which is the final cost.
  • The cost for "Mostafa" is 38$ for drinks, 33$ for delivery fees, which will be 71$, then 1$ is ignored to the nearest multiple of 5, so the final cost is 70$.
  • The cost for "Ahmad" is 26$ for drinks, 33$ for delivery fees, which will be 59$, then 1$ is ignored to the nearest multiple of 5, so the final cost is 60$.

Examples1

  1. Example 1

    Input
    1
    3 3
    cappuccino 28 34 41
    latte 25 31 38
    flatwhite 26 33 47
    Mohammed medium cappuccino
    Mostafa large latte
    Ahmad small flatwhite
    
    Expected output
    Mohammed 67
    Mostafa 70
    Ahmad 60