Setting

The famous gangster Vito "Did You Just Call Me Fat?" Deadstone is moving to New York. He has a very big family there, all of them living on Stay the Hell Away If You Want to Live Avenue. Since he will visit all his relatives very often, he wants to find a house close to them.

Indeed, Vito wants to minimize the total distance to all of his relatives and has blackmailed you into writing a program that solves his problem.

Input

The input consists of several test cases. The first line contains the number of test cases.

For each test case you will be given the integer number of relatives \(r\) (\(0 < r < 500\)) and the street numbers (also integers) \(s_1, s_2, \ldots, s_r\) where they live (\(0 < s_i < 30000\), \(1 \leq i \leq r\)). Note that several relatives might live at the same street number.

Output

For each test case, your program must write the minimal sum of distances from Vito's optimal street number to each one of his relatives. The distance between two street numbers \(s_i, s_j\) is \(d_{ij} = | s_i - s_j |\).

Sample Input

2
2 2 4
3 2 4 6

Sample Output

2
4

This is challenge 10041 of the ACM International Collegiate Programming Contest. Test input is provided by uDebug.

Upload Solution

Please log in to submit your solution.

Statistics

Difficulty (3 votes)
Average test runtime 0.36
Points (changes over time) 10
Tried by 28 users
Solved by 22 users

Global ranking

# Name Runtime Points worth
1 贝尔恩德 0.13 21
2 ,s/java/NaN/gi 0.15 18
3 Chris Danger 0.16 17
4 Pascal 0.16 17
5 Daniel 0.17 16
6 mascent 0.17 16
7 Nis 0.18 15
8 IeM 0.22 12
9 JB 0.23 12
10 Irfan 0.27 10
11 Mac 0.27 10
12 Finn-Lasse 0.45 6
13 Leif-Erik 0.48 6
14 Dark 0.49 6
15 YaAlex 0.49 6
16 Jona 0.51 5
17 Jan 0.52 5
18 Connor 0.52 5
19 Skøgland 0.55 5
20 Ansgar 0.56 5
21 Merle 0.56 5
22 Pascal 0.71 4