#K40682. Calculate Total Book Scores

    ID: 26697 Type: Default 1000ms 256MiB

Calculate Total Book Scores

Calculate Total Book Scores

You are given multiple test cases. For each test case, there are several participants and a collection of books with associated scores. Each participant has a reading list of book IDs. Your task is to compute the total score for each participant by summing the scores of the books they have read.

For each test case, the input format is as follows:

  • The first line contains two integers N and M: the number of participants and the number of books respectively.
  • The second line contains M space-separated integers, where the ith integer represents the score of the ith book.
  • Then follow N lines, one per participant. Each line begins with an integer K indicating the number of books that participant has read, followed by K space-separated integers representing the book IDs (1-indexed). If a participant has not read any book, the line will contain a single 0.

You need to output the total score for each participant on a separate line in the order of their appearance in the input. Process all test cases in order.

Note: All book IDs in each reading list will be valid (between 1 and M).

inputFormat

The input begins with an integer T, the number of test cases.

For each test case, the first line contains two integers N and M separated by a space, where N is the number of participants and M is the number of books.

The second line contains M space-separated integers B1, B2, ..., BM, representing the scores of the books.

Then N lines follow, each representing a participant's reading list. Each line starts with an integer K (the number of books read by the participant). If K > 0, it is followed by K space-separated integers which are the book IDs. If K is 0, then the participant did not read any book.

outputFormat

For each test case, output N lines. Each line should contain a single integer representing the total score of the corresponding participant.## sample

2
2 3
4 5 6
2 1 2
2 2 3
3 2
7 8
0
2 2 1
1 2
9

11 0 15 8

</p>