Stateside
Phoebe and Honey were watching the ice skating event at the Winter Olympics when they became fascinated by the shapes carved into the rink. Some skaters swept across the ice in smooth arcs, others crossed paths at just the right moment, and together their movements seemed to form a strange but beautiful Olympic pattern.
After the event, Phoebe tried to recreate the choreography on paper. She drew each skating path as a closed interval on a line and assigned it a beauty value based on how graceful the movement looked. Honey, impressed by the drawing but unwilling to let anything remain purely artistic, decided to turn the pattern into a challenge.
You are given closed intervals. The
-th interval is
and has a given beauty
.
An ordered 5-tuple of intervals is called Olympic if all of the following conditions hold:

The beauty of an Olympic 5-tuple is equal to the sum of the beauties of its five intervals.
For each test case, find the maximum possible beauty of an Olympic -tuple. If no Olympic
-tuple exists, print
.
Input
Each input contains multiple test cases. The first line contains
, the number of test cases.
The first line of each test case contains
, the number of intervals.
Each of the next lines contains three integers
,
, and
,
, describing the endpoints and beauty of the
-th interval.
It is guaranteed that the sum of over all test cases does not exceed
.
Output
For each test case, print a single integer: the maximum possible beauty of an Olympic 5-tuple, or if no such 5-tuple exists.
Examples
Input 1
2
5
1 3 1
2 4 2
3 6 3
5 7 4
6 8 5
5
1 3 10
2 4 10
3 5 10
5 7 10
6 8 10
Output 1
15
-1
Input 2
1
8
1 4 7
2 5 6
3 6 3
4 7 5
5 8 2
6 9 9
7 10 4
8 11 5
Output 2
32
Comments