本题来源于：2023 年“钉耙编程”中国大学生算法设计超级联赛第三场 第 9 题（HDUOJ 7308）
在一个游戏中，有 个角色，每个角色有三个属性 。
对于每一个角色 ，你可以将 变为 。你要将角色的差距最小化。
Little Q is playing an RPG online game. In this game, there are characters labeled by . The -th character has three types of quotas:
You are the team leader working for the new balance between these characters, aiming at bringing hope to the weak characters. For each character, your teammates have made a plan to strengthen some skills such that the three quotas may be increased as a result. Note that it is not allowed to weaken characters, because it will make their owners upset.
To make a perfect balance, you need to accept some plans and deny others such that the gap between all the characters is minimized. Note that a plan can only be entirely accepted or entirely denied. Here, the gap is defined as
The first line contains a single integer (), the number of test cases. For each test case:
The first line contains a single integer (), denoting the number of characters.
In the next lines, the -th line contains six integers , , , , and (, , ), describing the quotas of the -th character now and in plan.
It is guaranteed that the sum of all is at most .
For each test case, output a single line containing an integer, denoting the optimal gap.
1 2 1 1 1 2 3 5 2 4 3 7 5 8