This page is still under construction.

Parts of this page are still being built. What you see may change.

Misunderstood Missing

Time limit1sMemory limit256 MB

Summary
Each round, aggressivity grows by the current increment, then choose to attack, raise the increment by b_i, or raise aggressivity by c_i; maximize total damage.
Level

Medium7 of 10

Topics
Dynamic programming, Greedy
Solved
No attempts yet

Problem

Warm sunshine, cool wind and a fine day, while the girl watching is pursuing in chaos. Rikka reached out her hand and got the garland on her head, finding LCR with the immortal smile. The dream ended up waking, but the doubts will never disappear. In the end, without knowing about LCR, Rikka was invited to Shuyuan Men, a street of Chinese traditional arts in Xi'an.

"Is it enough to use the stored wires?"

"No problem... Those leaders are only concerned about expanding EC Final for the school's and their 'achievements'. All chores are ours. It is fine to simply connect those wiring boards in the series for each row."

Their conversation engaged Rikka. Feeling strange, she decided to follow them. But before all, she needs to beat the devil in her heart.

Rikka has an aggressivity AA and an increment DD of it, which are both 00 initially. There are nn rounds in total. For i=1,2,…,ni = 1, 2, \dots, n, at the beginning of ii-th round Rikka's aggressivity AA increases by the increment DD, and then she can do one of the following:

  1. Attack and cause a damage of (A+ai)(A + a_i).
  2. Use the Omnipotent Garland from LCR to increase the increment DD by bib_i.
  3. Use her Schwarz Sechs Prototype Mark II to increase the aggressivity AA by cic_i.

Rikka wonders the maximal possible damage she could cause in total. Could you help her?

Input

The first line contains a single integer T(1≤T≤10)T (1 \le T \le 10), the number of test cases. Then TT test cases follow.

The input format of each test case is as follows:

The first line contains a single integer n(1≤n≤100)n (1 \le n \le 100), the number of rounds.

The following nn lines contain {ai},{bi},{ci}\{a_i\}, \{b_i\}, \{c_i\} for i=1,2,…,ni = 1, 2, \dots , n. The ii-th line among them contains three integers ai,bi,ci(1≤ai,bi,ci≤109)a_i, b_i, c_i (1\le a_i, b_i, c_i \le 10^9) separated by spaces in order.

It is guaranteed that the sum of nn in all test cases is at most 100100.

Output

Output TT lines; each line contains one integer, the answer to that test case.

Examples1

  1. Example 1

    Input
    3
    2
    3 1 2
    3 1 2
    3
    3 1 2
    3 1 2
    3 1 2
    5
    3 1 2
    3 1 2
    3 1 2
    3 1 2
    3 1 2
    
    Expected output
    6
    10
    24