import java.util.;
import java.lang.;
import java.io.*;
/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner s=new Scanner(System.in);
int t=s.nextInt();
for(int i=0;i<t;i++)
{int n=s.nextInt();
int a[]=new int[n];
for(int j=0;j<n;j++)
a[j]=s.nextInt();
int count=0;
Arrays.sort(a);
for(int j=0;j<n-1;j++)
{count+=a[n-1]-a[j];}
System.out.println(count);
}
}}