1. 


/**
* 10041 - Vito's Family
*
* Studiengruppe: IFB2C
* Martin Pesl
* Robert Reichart
* Elvin Uzeirovic
*
* Run Time Submission Date
* 0.396 2009-07-07 12:28:06
*/


import java.io.*;
import java.util.Arrays;

public class Main {

public static void main(String... args) throws IOException{
Main a = new Main();
}

Main() throws IOException{
//öffnen des Inputs und auslesen der ersten zeile welche Anzahl cases beinhaltet
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String[] given;
int[] num;


for(int cases = Integer.parseInt(input.readLine()); cases > 0; cases--){
given = input.readLine().split("\\s+");
int count = Integer.parseInt(given[0]);
num = new int[count];
num[0] = Integer.parseInt(given[0]);
int min = num[0], max = num[1];

for(int i = 0; i < count; i++){
num[i] = Integer.parseInt(given[i+1]);
if(num[i] < min)min = num[i];
if(num[i] > max)max = num[i];
}
Arrays.sort(num);
//System.out.println(Arrays.toString(num));
int dist = 0;
int sum = 0;
if(count%2 == 0){
sum = Math.round(((float)num[(count/2)-1]+num[(count/2)])/2);
}else{
sum = num[(count/2)];
}
//System.out.println(sum);
for(int i = 0; i < count; i++){
dist += Math.abs(sum - num[i]);
}

System.out.println(dist);
}
}
}