#K84122. Library Fine Calculation

    ID: 36350 Type: Default 1000ms 256MiB

Library Fine Calculation

Library Fine Calculation

You are given a series of test cases representing library transactions. In each test case, a list of student names is provided followed by a series of transactions. Each transaction contains the student's name, the book's name, the day the book was borrowed, the due day, and the day the book was actually returned.

The fine for a transaction is calculated using the formula: $$f = \max(0,\,return\_day - due\_day)$$. For each student, the total fine is the sum of fines from all their transactions. If a student has no fine, output a message indicating no fines.

The output should retain the order of the students as they appear in the input.

inputFormat

The input begins with an integer T representing the number of test cases. Each test case is structured as follows:

  1. A line containing two integers N and B, where N is the number of students and B is the number of transactions.
  2. N lines, each containing a student's name.
  3. B transactions, each transaction consists of 5 lines:
    1. Student name
    2. Book name
    3. Borrowed day (integer)
    4. Due day (integer)
    5. Return day (integer)

All input is provided via standard input (stdin).

outputFormat

For each test case, output the fine details for every student in the order they were provided. For each student, print one line:

  • If the total fine is zero, print: "StudentName has no fines".
  • If the student owes a fine, print: "StudentName owes X", where X is the total fine.

The output should be written to standard output (stdout), with each student's result on a new line.

## sample
1
3 4
Anna
Chris
Laura
Anna
Book1
5
10
15
Chris
Book2
20
25
23
Laura
Book3
30
35
40
Anna
Book4
50
55
60
Anna owes 10

Chris has no fines Laura owes 5

</p>