Fundraising

Time limit1sMemory limit128 MB

Summary
Given a sequence of donation transactions, aggregate the amount each donor gave to each candidate and in total, then report every donor whose per-candidate total exceeds $2100 or whose overall total exceeds $40000. The core task is grouping and summing values by keys, then applying two threshold checks.
Level

Easy3 of 10

Topics
Hash map, Array, Implementation
Solved
No attempts yet

Problem

To even begin running a campaign, you need money. How else would you pay for annoying robo-calls, slanderous TV ads against your opponent, or all the suits you have to wear on the campaign trail? There are many ways to raise funds: old-fashioned donations, online ads, expensive fund-raising dinners, and more.

Because campaign donations can be construed (unfortunately, often rightly so) as buying influence over a candidate, campaign-finance laws limit the total amount any person may donate to a candidate or party. Under the law, any individual may contribute at most $2100 to any one candidate, and at most $40000 in total. When these donations are split across many transactions, though, it can be hard to figure out just how much someone gave.

Write a program that reads a sequence of individual donations and determines whether any limits were violated, and if so, which donors are the violators.

Input

The first line contains an integer K≥1K \ge 1, the number of data sets. It is followed by KK data sets of the following form.

The first line of a data set contains three integers cc, dd, tt with 1≤c≤1001 \le c \le 100, 1≤d≤10001 \le d \le 1000, and 1≤t≤1000001 \le t \le 100000. Here cc is the number of candidates (numbered 1,…,c1, \dots, c), dd is the number of donors (numbered 1,…,d1, \dots, d), and tt is the number of transactions.

This is followed by tt lines, each containing three integers did_i, cic_i, mim_i. This means that in transaction ii, donor did_i gave mim_i dollars to candidate cic_i. The same donor-candidate pair may appear multiple times.

Output

For each data set, first output the line Data Set x: by itself, where xx is the number of the data set. Then output either the single line No violations, or the line Violators: followed by every donor who broke at least one limit, one per line. List the donors in increasing order of donor number.

A donor is a violator if the total they gave to some single candidate exceeds $2100, or the total they gave across all candidates exceeds $40000.

Examples1

  1. Example 1

    Input
    2
    3 2 4
    1 1 1500
    1 2 500
    2 1 100
    2 3 2000
    3 2 4
    1 1 1500
    1 2 500
    2 3 2500
    1 2 1700
    
    Expected output
    Data Set 1:
    No violations
    Data Set 2:
    Violators:
    1
    2