#A2026C. 【KRUSKAL2026】Range Minimization

【KRUSKAL2026】Range Minimization

Problem Statement

The range of an array is defined as the difference between its maximum element and its minimum element.

You are given an integer array aa of length nn. You may perform the following operation any number of times, including zero times:

  • Choose two distinct indices ii and jj (1i,jn1\le i,j\le n and iji\ne j), and update the array as follows:
aiai+3,ajaj1.a_i\gets a_i+3,\qquad a_j\gets a_j-1.

Calculate the minimum possible range of aa after performing any finite number of operations.

Input Format

The input contains multiple test cases.

The first line contains an integer TT (1T1041 \le T \le 10^4), the number of test cases.

For each test case:

  • The first line contains an integer nn (1n2×1051 \le n \le 2 \times 10^5), the length of the array aa.
  • The second line contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n (109ai109-10^9 \leq a_i \leq 10^9), the elements of aa.

It is guaranteed that n2×105\sum n \leq 2 \times 10^5 over all test cases.

Output Format

For each test case, output one integer on a separate line: the minimum possible range after performing any finite number of operations.

Sample

Sample Input

3
1
5
2
0 2
4
-1 9 5 8

Sample Output

0
2
1

Explanation

  • In the first test case, the array contains only one element, so its range is always 00.