#P1746G. Olympiad Training

    ID: 7996 Type: RemoteJudge 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 10 Uploaded By: Tags>binary searchdata structuresdpflowsgeometryimplementationsortings*3500

Olympiad Training

No submission language available for this problem.

Description

Anton decided to get ready for an Olympiad in Informatics. Ilya prepared nn tasks for him to solve. It is possible to submit the solution for the ii-th task in the first did_{i} days only. Anton cannot solve more than one task a day. Ilya estimated the usefulness of the ii-th tasks as rir_{i} and divided the tasks into three topics, the topic of the ii-th task is typeitype_{i}.

Anton wants to solve exactly aa tasks on the first topic, bb tasks on the second topic and cc tasks on the third topic. Tell Anton if it is possible to do so, and if it is, calculate the maximum total usefulness of the tasks he may solve.

The first line of input contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains four integers n,a,b,cn, a, b, c (1n1051 \le n \le 10^5, 0a,b,cn0 \le a, b, c \le n).

The following nn lines contain three integers each — ri,typei,dir_i, type_i, d_i (0ri1090 \le r_i \le 10^{9}, 1typei31 \le type_i \le 3, 1din1 \le d_i \le n).

The sum of nn over all test cases does not exceed 10510^5.

For each test case print 1-1 if Anton cannot reach his goal; otherwise, print the maximum usefulness of the tasks he will solve.

Input

The first line of input contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains four integers n,a,b,cn, a, b, c (1n1051 \le n \le 10^5, 0a,b,cn0 \le a, b, c \le n).

The following nn lines contain three integers each — ri,typei,dir_i, type_i, d_i (0ri1090 \le r_i \le 10^{9}, 1typei31 \le type_i \le 3, 1din1 \le d_i \le n).

The sum of nn over all test cases does not exceed 10510^5.

Output

For each test case print 1-1 if Anton cannot reach his goal; otherwise, print the maximum usefulness of the tasks he will solve.

Sample Input 1

4
4 1 1 0
1 2 1
1 1 1
0 1 2
1 2 2
3 1 1 1
1 1 2
7 2 1
9 3 2
4 2 1 0
100 2 1
5 2 3
7 1 2
5 1 2
5 1 1 1
10 3 1
9 2 3
20 1 1
16 1 4
1 3 4

Sample Output 1

2
-1
17
35

Note

In the first test case from the sample test Anton can solve tasks 22 and 44.

In the second test case from the sample test it is impossible to fulfill Anton's wish.

In the third test case from the sample test it is optimal to solve tasks 22, 33 and 44.

In the last test case from the sample test it is optimal to solve tasks 11, 22 and 44.