This page is still under construction.

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

Command and Conquer: Red Alert 2

Time limit10sMemory limit512 MB

Summary
Find the smallest Chebyshev range k so a sniper moving only in +x, +y, or +z steps from far away can cover all enemies in 3D.
Level

Hard8 of 10

Topics
Binary search, Greedy, Sorting
Solved
No attempts yet

Problem

Nocriz is a nostalgic boy who loves watching HBK08 and Lantian28 play Command and Conquer: Red Alert 2. However, he does not know how to play the game himself.

In the game, you own a sniper initially located at (−10100,−10100,−10100)(-10^{100}, -10^{100}, -10^{100}) in a 3D world. There are nn enemy soldiers, where the ii-th soldier is located at (xi,yi,zi)(x_i, y_i, z_i). We say the range of the sniper is kk if the sniper can kill all enemies such that max⁡(∣xs−xe∣,∣ys−ye∣,∣zs−ze∣)≤k\max(|x_s - x_e|, |y_s - y_e|, |z_s - z_e|) \le k, where (xs,ys,zs)(x_s, y_s, z_s) is the location of the sniper and (xe,ye,ze)(x_e, y_e, z_e) is the location of the enemy.

In one step, the sniper can move from (x,y,z)(x, y, z) to (x+1,y,z)(x + 1, y, z), (x,y+1,z)(x, y + 1, z), or (x,y,z+1)(x, y, z + 1). The enemies do not move. The sniper may make an unlimited number of steps and may kill all enemies in range whenever all of its coordinates are integers. What is the minimum range kk such that the sniper can eventually kill all enemies?

Input

The first line contains an integer TT (1≤T≤5⋅1041 \le T \le 5 \cdot 10^4), the number of test cases. Then TT test cases follow.

The first line of each test case contains a single integer nn (1≤n≤5⋅1051 \le n \le 5 \cdot 10^5), the number of enemies.

Then nn lines follow, each containing three integers xix_i, yiy_i, ziz_i (−109≤xi,yi,zi≤109-10^9 \le x_i, y_i, z_i \le 10^9) denoting the location of the ii-th enemy.

It is guaranteed that ∑n≤2⋅106\sum n \le 2 \cdot 10^6.

Output

For each test case, output a line with a single integer representing the minimum range kk.

Examples1

  1. Example 1

    Input
    3
    2
    0 0 0
    1 1 1
    2
    0 1 0
    1 0 1
    5
    1 1 4
    5 1 4
    1 9 1
    9 8 1
    0 0 0
    
    Expected output
    0
    1
    2