Under construction

Still being built. Things may change

Three Investigators

Time limit5sMemory limit512 MB

Summary
For each prefix length k, find the maximum total sum of at most 5 disjoint non-decreasing subsequences taken from that prefix.
Level

Hard9 of 10

Topics
Dynamic programming, Divide and conquer, Array
Solved
No attempts yet

Problem

Chitanda owns a sequence a1,a2,…,ana_1, a_2, \ldots, a_n of nn integers, and she wants to play a game with Skywalkert.

First, Chitanda selects a parameter kk and removes ak+1,ak+2,…,ana_{k+1}, a_{k+2}, \ldots, a_n. Then exactly kk integers remain in the sequence aa.

Next, Skywalkert can select a subsequence of aa and remove it from aa. If the selected subsequence is ap1,ap2,…,apma_{p_1}, a_{p_2}, \ldots, a_{p_m}, then p1<p2<…<pmp_1 < p_2 < \ldots < p_m and ap1≤ap2≤…≤apma_{p_1} \le a_{p_2} \le \ldots \le a_{p_m} must hold.

Skywalkert can perform this operation at most 5 times. His score is the sum of all integers he selects in these operations.

For each possible parameter kk that Chitanda selects, find the maximum score Skywalkert can achieve.

Input

The first line contains an integer TT (1≤T≤100001 \le T \le 10000), the number of test cases.

Each test case has one line with an integer nn (1≤n≤1000001 \le n \le 100000), the length of the sequence. The next line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9).

The sum of nn over all test cases is at most 500000.

Output

For each test case, print one line with nn integers s1,s2,…,sns_1, s_2, \ldots, s_n separated by spaces, where sis_i is the maximum score Skywalkert can achieve when k=ik = i.

Examples1

  1. Example 1

    Input
    1
    8
    8 7 6 5 1 3 2 4
    
    Expected output
    8 15 21 26 27 30 30 34