#P9818. King's Ruins

King's Ruins

King's Ruins

Problem Description

The first king of Byteland was buried with his nn knights a thousand years ago. In the ruins, the archaeologists have found nn stone tablets in a row, labeled by 1,2,,n1,2,\dots,n from left to right. Each stone tablet belongs to a knight. On the surface of the kk-th stone tablet, five numbers are describing the ability of the kk-th knight in five aspects:

  • The wind ability ww, denoting how fast the knight is.
  • The guard ability gg, denoting how many attacks can be defended by the knight.
  • The ice ability ii, denoting the power of ice crystal cast by the knight.
  • The flame ability ff, denoting the power of fire cast by the knight.
  • The light ability ll, denoting the power of thunder cast by the knight. Little Q is visiting the stone tablets from left to right, according to the labels from 11 to nn. After visiting a stone tablet, before moving right to the next one, he can choose to take a photo with it or do nothing. Little Q estimates the value of each stone tablet, he wants to maximize the total value that he takes photos with, and the knight corresponding to the next photo is always not weaker than the current one. Here the xx-th knight is considered not to be weaker than the yy-th knight if and only if wxwyw_x\geq w_y, gxgyg_x\geq g_y, ixiyi_x\geq i_y, fxfyf_x\geq f_y and lxlyl_x\geq l_y. There are so many stone tablets that Little Q can not determine which to take photos with. Please write a program to help him.

Input

The first line contains a single integer TT (1T51 \leq T \leq 5), the number of test cases. For each test case: The first line contains a single integer nn (1n500001 \leq n \leq 50\,000), denoting the number of stone tablets. In the next nn lines, the kk-th line contains six integers wkw_k, gkg_k, iki_k, fkf_k, lkl_k and vkv_k (1wk,gk,ik,fk,lkn1\leq w_k,g_k,i_k,f_k,l_k\leq n, 1vk100001\leq v_k\leq 10\,000), describing the kk-th stone tablet, vkv_k denoting the value of the photo with it.

Output

For each test case, output nn lines, the kk-th (1kn1\leq k\leq n) of which containing an integer, denoting the maximum total value when the last photo is taken with the kk-th stone tablet.

Sample Input

1
4
1 2 1 2 1 30
2 1 2 1 2 40
3 3 3 3 3 50
2 3 3 2 4 100

Sample Output

30
40
90
140

Source

2023“钉耙编程”中国大学生算法设计超级联赛(3)