시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 512 MB 1 1 1 100.000%

## 문제

1Class-action lawyers

## 입력

The first line contains a number K ≥ 1, which is the number of input data sets in the file. This is followed by K data sets of the following form:

The first line of each data set contains two integers n, v. 2 ≤ n ≤ 1000 is the number of ads the site has as customers, and 0 ≤ v ≤ 1000 is the number of visitors to the site.

This is followed by n lines, each describing one ad i with two integers di, pi. The number di will always be either 0 or 1; a value of 1 means that the ad is a display ad (the site gets paid just for displaying it), and a value of 0 means that the ad is a clickthrough ad (the site only gets paid when the user clicks on it). 1 ≤ pi ≤ 1000 is the payment for the ad, which will be paid for displaying it (display ad) or clicking it (clickthrough ad).

Next come v lines, each describing one visitor j with three integers aj,1, aj,2, cj . The first two numbers aj,1, aj,2 are the two ads the user is shown when visiting the site; they will be distinct and will always be between 1 and n, inclusive. The number cj ∈ {0, 1, 2} is the ad the user clicked on. A value of 0 means the user did not click on anything, 1 means that the user clicked on aj,1, and 2 means that he/she clicked on aj,2. Notice that a user might click on a display ad — the site does not get extra payment for this.

## 출력

For each data set, first output “Data Set x:” on a line by itself, where x is its number. Then, output the total payment that the fake news site receives.

Each data set should be followed by a blank line.

## 예제 입력 1

2
3 3
1 10
1 15
0 100
1 2 0
2 3 2
1 3 0
2 3
1 9
0 13
1 2 0
1 2 1
1 2 2


## 예제 출력 1

Data Set 1:
150

Data Set 2:
40