Under construction

Still being built. Things may change

Team Training

Time limit1sMemory limit2048 MB

Summary
Given 3n distinct levels, repeatedly remove three consecutive students into teams 1, 2, 3, maximizing the team sums lexicographically; output the three sums.
Level

Medium6 of 10

Topics
Dynamic programming, Array, Greedy
Solved
No attempts yet

Problem

Today, Amir had another training session with his coach Timo from Kazakhstan.

Today, Timo had 3n3n students at his training session. Each student, indexed as ii, had their own level denoted as pip_i. All students had different levels.

Usually, Timo divided the students into teams of three participants. Today, however, he decided to change the system and divide the students into three teams. He selected three consecutive students from the list and sent the first one to the first team, the second one to the second team, and the third one to the third team. Then he crossed out these three students from the list and repeated the process until all students were distributed.

The level of a team is the sum of the levels of its participants. Timo wanted to maximize the level of the first team. If several options maximized it, he maximized the level of the second team. If several options still remained, he maximized the level of the third team.

For example, take the list [3,1,5,4,2,6][3, 1, 5, 4, 2, 6]. If Timo first chose [1,5,4][1, 5, 4] and then [3,2,6][3, 2, 6], the team levels would be [1+3,5+2,4+6]=[4,7,10][1+3, 5+2, 4+6] = [4, 7, 10]. If he chose [5,4,2][5, 4, 2] first and then [3,1,6][3, 1, 6], the team levels would be [8,5,8][8, 5, 8], which is the better distribution by the criteria.

Find the levels of the teams when Timo divides the students optimally.

Input

The first line contains a single integer tt (1≤t≤1051 \le t \le 10^5), the number of test cases. Each test case is given as follows.

The first line contains an integer nn (1≤n≤1051 \le n \le 10^5), the number of students.

The second line contains 3n3n distinct integers p1,p2,…,p3np_1, p_2, \ldots, p_{3n} (1≤pi≤3n1 \le p_i \le 3n), the levels of the students.

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

Output

Output a line with three integers: the levels of the first, second, and third teams in the optimal division.

Examples1

  1. Example 1

    Input
    2
    1
    2 3 1
    2
    3 1 5 4 2 6
    
    Expected output
    2 3 1
    8 5 8