The Minimum Number Of Moves

All submissions for this problem are available.
Little chief has his own restaurant in the city. There are N workers there. Each worker has his own salary. The salary of the ith worker equals to W_{i} (i = 1, 2, ..., N). Once, chief decided to equalize all workers, that is, he wants to make salaries of all workers to be equal. But for this goal he can use only one operation: choose some worker and increase by 1 salary of each worker, except the salary of the chosen worker. In other words, the chosen worker is the loser, who will be the only worker, whose salary will be not increased during this particular operation. But loserworker can be different for different operations, of course. Chief can use this operation as many times as he wants. But he is a busy man. That's why he wants to minimize the total number of operations needed to equalize all workers. Your task is to find this number.
Input
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of workers. The second line contains N spaceseparated integers W_{1}, W_{2}, ..., W_{N} denoting the salaries of the workers.
Output
For each test case, output a single line containing the minimum number of operations needed to equalize all workers.
Constraints
 1 ≤ T ≤ 100
 1 ≤ N_{} ≤ 100
 0 ≤ W_{i} ≤ 10000 (10^{4})
Example
Input: 2 3 1 2 3 2 42 42 Output: 3 0
Explanation
Example Case 1. Chief can equalize all salaries in 3 turns:
Turn ID  IDs of involved workers  Salaries after the move 
1  1 2  2 3 3 
2  1 2  3 4 3 
3  1 3  4 4 4 
Example Case 2. All salaries are already equal. He doesn't need to do anything.
Author:  ballon_ziq 
Tester:  anton_lunyov 
Editorial  http://discuss.codechef.com/problems/SALARY 
Tags  adhoc ballon_ziq cakewalk jan13 
Date Added:  24102012 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.9.2, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.4, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 