import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Main {
	public static long max (long a[] , int n) {
		long max = a[0];
		for(int i = 0; i<n; i++) {
			max = Math.max(max, a[i]);
		}
		return max;
	}
	public static void solve(InputReader in) {
		int n = in.readInt(), k = in.readInt();
		long a[] = new long[n];

		for(int i = 0; i<n; i++)
			a[i] = in.readInt();

		long max = max(a , n);

		for(int i = 0; i<n; i++)
			a[i] = max - a[i];

		max = max(a , n);

		if(k == 1) for(int i = 0; i<n; i++) System.out.print(a[i] + " ");
		else {
			     k--;
			     if(k%2 != 0) {
			    	     for(int i =0; i<n; i++) {
			    	    	 System.out.print(max - a[i] + " ");
			    	     }
			     }
			     else {
			    	   for(int i = 0; i<n; i++) {
			    		   System.out.print(a[i] + " " );
			    	   }
			     }
		}
		System.out.println();
	}

	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		int t = in.readInt();
		while (t-- > 0)
			solve(in);
	}
}

class InputReader{
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	 public InputReader(InputStream stream) {
		this.stream = stream;
	}

     public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

     public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

     public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

     public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

     public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

     public String next() {
		return readString();
	}

     public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Main {
	public static void solve(InputReader in) {
		int n = in.readInt();
		int k = in.readInt();
		ArrayList<Integer> a = new ArrayList<>();
		for(int i = 0; i<n; i++) {
			a.add(in.readInt());
		}
		int max = Collections.max(a);
		for(int i = 0; i<n; i++) {
			System.out.print(max - a.get(i) + " ");
		}
		System.out.println();
	}

	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		int t = in.readInt();
		while (t-- > 0)
			solve(in);
	}
}

class InputReader{
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	 public InputReader(InputStream stream) {
		this.stream = stream;
	}

     public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

     public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

     public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

     public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

     public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

     public String next() {
		return readString();
	}

     public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


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

public class Main {
	public static long max (long a[] , int n) {
		long max = a[0];
		for(int i = 0; i<n; i++) {
			max = Math.max(max, a[i]);
		}
		return max;
	}
	public static void solve(InputReader in) {
		int n = in.readInt(), k = in.readInt();
		long a[] = new long[n];

		for(int i = 0; i<n; i++)
			a[i] = in.readInt();

		long max = max(a , n);

		for(int i = 0; i<n; i++)
			a[i] = max - a[i];

		max = max(a , n);
			     k--;
			     if(k % 2 == 0) {
			    	 for(int i = 0; i<n; i++) {
			    		   System.out.print(a[i] + " " );
			    	   }
			     }
			     else {
			    	   for(int i =0; i<n; i++) {
			    	    	 System.out.print(max - a[i] + " ");
			    	     }
			     }
		System.out.println();
	}

	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		int t = in.readInt();
		while (t-- > 0)
			solve(in);
	}
}

class InputReader{
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	 public InputReader(InputStream stream) {
		this.stream = stream;
	}

     public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

     public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

     public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

     public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

     public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

     public String next() {
		return readString();
	}

     public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Main {
	public static int max (int a[] , int n) {
		int max = a[0];
		for(int i = 0; i<n; i++) {
			max = Math.max(max, a[i]);
		}
		return max;
	}
	public static void solve(InputReader in) {
		int n = in.readInt(), k = in.readInt();
		int a[] = new int[n];

		for(int i = 0; i<n; i++)
			a[i] = in.readInt();

		int max = max(a , n);

		for(int i = 0; i<n; i++)
			a[i] = max - a[i];

		max = max(a , n);

		if(k == 1) for(int i = 0; i<n; i++) System.out.print(a[i] + " ");
		else {
			     k--;
			     if(k % 2 == 1) {
			    	     for(int i =0; i<n; i++) {
			    	    	 System.out.print(max - a[i] + " ");
			    	     }
			     }
			     else {
			    	   for(int i = 0; i<n; i++) {
			    		   System.out.print(a[i] + " " );
			    	   }
			     }
		}
		System.out.println();
	}

	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		int t = in.readInt();
		while (t-- > 0)
			solve(in);
	}
}

class InputReader{
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	 public InputReader(InputStream stream) {
		this.stream = stream;
	}

     public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

     public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

     public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

     public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

     public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

     public String next() {
		return readString();
	}

     public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Solution2 {
  static int n;
  static int m;

  public static void main(String args[]) {
    Scanner in = new Scanner(System.in);
    n = 3;
    n = in.nextInt();
    for (int i = 0; i < n; i++) {
      int N = in.nextInt();
      int nbOp = in.nextInt();
      List<Integer> array = new ArrayList<>();
      int max = Integer.MIN_VALUE;
      for (int j = 0; j < N; j++) {
        int tmp = in.nextInt();
        array.add(tmp);
        max = Math.max(tmp, max);
      }
      for (int k = 0; k < nbOp; k++) {
       int  oldMax = max;
       max = Integer.MIN_VALUE;
        for (int j = 0; j < N; j++) {
          int tmp = oldMax - array.get(j);
          array.set(j, tmp);
          max = Math.max(tmp, max);
        }
      }
      System.out.println(Stream.of(array).map(y -> "" + y).collect(Collectors.joining(" ")));
    }
  }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Solution2 {
  static int n;
  static int m;

  public static void main(String args[]) {
    Scanner in = new Scanner(System.in);
    n = 3;
    n = in.nextInt();
    for (int i = 0; i < n; i++) {
      int N = in.nextInt();
      long nbOp = in.nextLong();
      List<Integer> array = new ArrayList<>();
      int max = Integer.MIN_VALUE;
      for (int j = 0; j < N; j++) {
        int tmp = in.nextInt();
        array.add(tmp);
        max = Math.max(tmp, max);
      }
      for (long k = 0; k < nbOp; k++) {
       int  oldMax = max;
       max = Integer.MIN_VALUE;
        for (int j = 0; j < N; j++) {
          int tmp = oldMax - array.get(j);
          array.set(j, tmp);
          max = Math.max(tmp, max);
        }
      }
      System.out.println(array.stream().map(y -> "" + y).collect(Collectors.joining(" ")));
    }
  }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Solution2 {
  static int n;
  static int m;

  public static void main(String args[]) {
    Scanner in = new Scanner(System.in);
    n = 3;
    n = in.nextInt();
    for (int i = 0; i < n; i++) {
      int N = in.nextInt();
      long nbOp = in.nextLong();
      List<Integer> array = new ArrayList<>();
      int max = Integer.MIN_VALUE;
      int min = Integer.MAX_VALUE;

      for (int j = 0; j < N; j++) {
        int tmp = in.nextInt();
        array.add(tmp);
        max = Math.max(tmp, max);
        min = Math.min(tmp, min);
      }
      for (int j = 0; j < N; j++) {
        int tmp = nbOp % 2 == 1 ? max - array.get(j) : (-min + array.get(j));
        array.set(j, tmp);
      }
      System.out.println(array.stream().map(y -> "" + y).collect(Collectors.joining(" ")));
    }
  }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Solution2 {
  static int n;
  static int m;

  public static void main(String args[]) {
    Scanner in = new Scanner(System.in);
    n = 3;
    n = in.nextInt();
    for (int i = 0; i < n; i++) {
      int N = in.nextInt();
      long nbOp = in.nextLong();
      List<Integer> array = new ArrayList<>();
      int max = Integer.MIN_VALUE;
      int min = Integer.MAX_VALUE;

      for (int j = 0; j < N; j++) {
        int tmp = in.nextInt();
        array.add(tmp);
        max = Math.max(tmp, max);
        min = Math.min(tmp, max);
      }
      for (int j = 0; j < N; j++) {
        int tmp = nbOp % 2 == 1 ? max - array.get(j) : (-min + array.get(j));
        array.set(j, tmp);
      }
      System.out.println(array.stream().map(y -> "" + y).collect(Collectors.joining(" ")));
    }
  }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Solution2 {
  static int n;
  static int m;

  public static void main(String args[]) {
    Scanner in = new Scanner(System.in);
    n = 3;
    n = in.nextInt();
    for (int i = 0; i < n; i++) {
      int N = in.nextInt();
      int nbOp = in.nextInt();
      List<Integer> array = new ArrayList<>();
      int max = Integer.MIN_VALUE;
      for (int j = 0; j < N; j++) {
        int tmp = in.nextInt();
        array.add(tmp);
        max = Math.max(tmp, max);
      }
      for (int k = 0; k < nbOp; k++) {
       int  oldMax = max;
       max = Integer.MIN_VALUE;
        for (int j = 0; j < N; j++) {
          int tmp = oldMax - array.get(j);
          array.set(j, tmp);
          max = Math.max(tmp, max);
        }
      }
      System.out.println(array.stream().map(y -> "" + y).collect(Collectors.joining(" ")));
    }
  }
}


import java.util.*;
public class Solution{
    public static void main(String[] args){
        Scanner ip =new Scanner(System.in);
        int t = ip.nextInt();

        while(t-- >0){
            int n =ip.nextInt();
            long k =ip.nextLong();
            long[] nums =new long[n];
            int max = Integer.MIN_VALUE ;
            for(int i=0;i<n;i++){
                nums[i] = ip.nextLong();
                max =Math.max(max,nums[i]);
            }

            for(int i=0;i<n;i++){
                nums[i] = max- nums[i];
                max =Math.max(max,nums[i]);
            }
            if(k%2 !=0){
                for(int i=0;i<n;i++){
                    System.out.printf("%d ",nums[i]);
                }
                System.out.println();
            }
            else{
                for(int i=0;i<n;i++){
                    nums[i] = max- nums[i];
                    System.out.printf("%d ",nums[i]);
                }
                System.out.println();
            }
        }
    }
}


import java.util.*;
public class Solution{
    public static void main(String[] args){
        Scanner ip =new Scanner(System.in);
        int t = ip.nextInt();

        while(t-- >0){
            int n =ip.nextInt();
            long k =ip.nextLong();
            long[] nums =new long[n];
            long max = Integer.MIN_VALUE ;
            for(int i=0;i<n;i++){
                nums[i] = ip.nextLong();
                max =Math.max(max,nums[i]);
            }

            for(int i=0;i<n;i++){
                nums[i] = max- nums[i];
                max =Math.max(max,nums[i]);
            }
            if(k%2 !=0){
                for(int i=0;i<n;i++){
                    System.out.printf("%d ",nums[i]);
                }
                System.out.println();
            }
            else{
                for(int i=0;i<n;i++){
                    nums[i] = max- nums[i];
                    System.out.printf("%d ",nums[i]);
                }
                System.out.println();
            }
        }
    }
}


import java.util.*;
public class Solution{
    public static void main(String[] args){
        Scanner ip =new Scanner(System.in);
        int t = ip.nextInt();

        while(t-- >0){
            int n =ip.nextInt();
            long k =ip.nextLong();
            long[] nums =new long[n];
            long max = Integer.MIN_VALUE ;
            for(int i=0;i<n;i++){
                nums[i] = ip.nextLong();
                max =Math.max(max,nums[i]);
            }
            long maxx = Integer.MIN_VALUE ;
            for(int i=0;i<n;i++){
                nums[i] = max- nums[i];
                maxx =Math.max(maxx,nums[i]);
            }
            if(k%2 !=0){
                for(int i=0;i<n;i++){
                    System.out.printf("%d ",nums[i]);
                }
                System.out.println();
            }
            else{
                for(int i=0;i<n;i++){
                    nums[i] = maxx- nums[i];
                    System.out.printf("%d ",nums[i]);
                }
                System.out.println();
            }
        }
    }
}


import java.io.*;
import java.awt.Rectangle;
import java.util.*;

public class problemA
{
   public static void main (String[] args) throws IOException
   {
      BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
      //BufferedReader input = new BufferedReader(new FileReader("diamond.in"));
      //PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("diamond.out")));
      StringTokenizer token = new StringTokenizer(input.readLine());
      int maxCount = Integer.parseInt(token.nextToken());
      for(int b = 0; b < maxCount; b++)
      {
         token = new StringTokenizer(input.readLine());
         int arrayLength = Integer.parseInt(token.nextToken());
         long operations = Long.parseLong(token.nextToken());
         int [] array = new int[arrayLength];
         token = new StringTokenizer(input.readLine());
         int max = Integer.MIN_VALUE;
         for(int x = 0; x < arrayLength; x++)
         {
            array[x] = Integer.parseInt(token.nextToken());
            if(array[x] > max)
               max = array[x];
         }

         operations--;
         int max2 = Integer.MIN_VALUE;
         for(int x = 0; x < arrayLength; x++)
         {
            array[x] = max - array[x];
            if(array[x] > max2)
               max2 = array[x];
         }
         operations = operations % 2;
         if(operations == 0)
         {
            for(int x = 0; x < arrayLength; x++)
               System.out.print(array[x] + " ");
            System.out.println();
         }
         else
         {
            for(int x = 0; x < arrayLength; x++)
            {
               array[x] = max2 - array[x];
               System.out.print(array[x] + " ");
            }
            System.out.println();
         }

      }
   }
}


import java.io.*;
import java.awt.Rectangle;
import java.util.*;

public class problemA
{
   public static void main (String[] args) throws IOException
   {
      BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
      //BufferedReader input = new BufferedReader(new FileReader("diamond.in"));
      //PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("diamond.out")));
      StringTokenizer token = new StringTokenizer(input.readLine());
      int maxCount = Integer.parseInt(token.nextToken());
      for(int b = 0; b < maxCount; b++)
      {
         token = new StringTokenizer(input.readLine());
         int arrayLength = Integer.parseInt(token.nextToken());
         int operations = Integer.parseInt(token.nextToken());
         int [] array = new int[arrayLength];
         token = new StringTokenizer(input.readLine());
         int max = 0;
         for(int x = 0; x < arrayLength; x++)
         {
            array[x] = Integer.parseInt(token.nextToken());
            if(array[x] > max)
               max = array[x];
         }
         operations--;
         int max2 = 0;
         for(int x = 0; x < arrayLength; x++)
         {
            array[x] = max - array[x];
            if(array[x] > max2)
               max2 = array[x];
         }
         operations = operations % 2;
         if(operations == 0)
         {
            for(int x = 0; x < arrayLength; x++)
            {
               System.out.print(array[x] + " ");
            }
            System.out.println();
         }
         else
         {
            for(int x = 0; x < arrayLength; x++)
            {
               array[x] = max2 - array[x];
               System.out.print(array[x] + " ");
            }
            System.out.println();
         }

      }

   }
}


import java.io.*;
import java.awt.Rectangle;
import java.util.*;

public class problemA
{
   public static void main (String[] args) throws IOException
   {
      BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
      //BufferedReader input = new BufferedReader(new FileReader("diamond.in"));
      //PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("diamond.out")));
      StringTokenizer token = new StringTokenizer(input.readLine());
      int maxCount = Integer.parseInt(token.nextToken());
      for(int b = 0; b < maxCount; b++)
      {
         token = new StringTokenizer(input.readLine());
         int arrayLength = Integer.parseInt(token.nextToken());
         int operations = Integer.parseInt(token.nextToken());
         int [] array = new int[arrayLength];
         token = new StringTokenizer(input.readLine());
         int max = Integer.MIN_VALUE;
         for(int x = 0; x < arrayLength; x++)
         {
            array[x] = Integer.parseInt(token.nextToken());
            if(array[x] > max)
               max = array[x];
         }
         operations = operations % 2;
         if(operations == 1)
         {
            for(int x = 0; x < arrayLength; x++)
            {
               array[x] = max - array[x];
               System.out.print(array[x] + " ");
            }
            System.out.println();
         }
         else
         {
            int max2 = Integer.MIN_VALUE;
            for(int x = 0; x < arrayLength; x++)
            {
               array[x] = max - array[x];
               if(array[x] > max2)
                  max2 = array[x];
            }
            for(int x = 0; x < arrayLength; x++)
            {
               array[x] = max2 - array[x];
               System.out.print(array[x] + " ");
            }
            System.out.println();
         }
      }

   }
}


import java.io.*;
import java.awt.Rectangle;
import java.util.*;

public class problemA
{
   public static void main (String[] args) throws IOException
   {
      BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
      //BufferedReader input = new BufferedReader(new FileReader("diamond.in"));
      //PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("diamond.out")));
      StringTokenizer token = new StringTokenizer(input.readLine());
      int maxCount = Integer.parseInt(token.nextToken());
      for(int b = 0; b < maxCount; b++)
      {
         token = new StringTokenizer(input.readLine());
         int arrayLength = Integer.parseInt(token.nextToken());
         int operations = Integer.parseInt(token.nextToken());
         int [] array = new int[arrayLength];
         token = new StringTokenizer(input.readLine());
         int max = Integer.MIN_VALUE;
         for(int x = 0; x < arrayLength; x++)
         {
            array[x] = Integer.parseInt(token.nextToken());
            if(array[x] > max)
               max = array[x];
         }
         operations = operations % 2;
         if(operations == 1)
         {
            String s = "";
            for(int x = 0; x < arrayLength; x++)
            {
               array[x] = max - array[x];
               s = s + array[x] + " ";
            }
            s.trim();
            System.out.println(s);
         }
         else
         {
            String s = "";
            int max2 = Integer.MIN_VALUE;
            for(int x = 0; x < arrayLength; x++)
            {
               array[x] = max - array[x];
               if(array[x] > max2)
                  max2 = array[x];
            }
            for(int x = 0; x < arrayLength; x++)
            {
               array[x] = max2 - array[x];
               s = s + array[x] + " ";
            }
            s.trim();
            System.out.println(s);
         }
      }

   }
}


import java.io.*;
import java.awt.Rectangle;
import java.util.*;

public class problemA
{
   public static void main (String[] args) throws IOException
   {
      BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
      //BufferedReader input = new BufferedReader(new FileReader("diamond.in"));
      //PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("diamond.out")));
      StringTokenizer token = new StringTokenizer(input.readLine());
      int maxCount = Integer.parseInt(token.nextToken());
      for(int b = 0; b < maxCount; b++)
      {
         token = new StringTokenizer(input.readLine());
         int arrayLength = Integer.parseInt(token.nextToken());
         long operations = Long.parseLong(token.nextToken());
         int [] array = new int[arrayLength];
         token = new StringTokenizer(input.readLine());
         int max = Integer.MIN_VALUE;
         for(int x = 0; x < arrayLength; x++)
         {
            array[x] = Integer.parseInt(token.nextToken());
            if(array[x] > max)
               max = array[x];
         }

         operations = operations % 2;
         if(operations == 1)
         {
            String s = "";
            for(int x = 0; x < arrayLength; x++)
            {
               array[x] = max - array[x];
               s = s + array[x] + " ";
            }
            s.trim();
            System.out.println(s);
         }
         else
         {
            String s = "";
            int max2 = Integer.MIN_VALUE;
            for(int x = 0; x < arrayLength; x++)
            {
               array[x] = max - array[x];
               if(array[x] > max2)
                  max2 = array[x];
            }
            for(int x = 0; x < arrayLength; x++)
            {
               array[x] = max2 - array[x];
               s = s + array[x] + " ";
            }
            s.trim();
            System.out.println(s);
         }

      }
   }
}


import java.io.*;
import java.awt.Rectangle;
import java.util.*;

public class problemA
{
   public static void main (String[] args) throws IOException
   {
      BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
      //BufferedReader input = new BufferedReader(new FileReader("diamond.in"));
      //PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("diamond.out")));
      StringTokenizer token = new StringTokenizer(input.readLine());
      int maxCount = Integer.parseInt(token.nextToken());
      for(int b = 0; b < maxCount; b++)
      {
         token = new StringTokenizer(input.readLine());
         int arrayLength = Integer.parseInt(token.nextToken());
         int operations = Integer.parseInt(token.nextToken());
         int [] array = new int[arrayLength];
         token = new StringTokenizer(input.readLine());
         for(int x = 0; x < arrayLength; x++)
         {
            array[x] = Integer.parseInt(token.nextToken());
         }
         for(int y = 1; y <= operations; y++)
         {
            int max = Integer.MIN_VALUE;
            for(int x = 0; x < arrayLength; x++)
            {
               if(array[x] > max)
                  max = array[x];
            }
            for(int x = 0; x < arrayLength; x++)
            {
               array[x] = max - array[x];
            }
         }
         /*
         operations = operations % 2;
         if(operations == 1)
         {
            String s = "";
            for(int x = 0; x < arrayLength; x++)
            {
               array[x] = max - array[x];
               s = s + array[x] + " ";
            }
            s.trim();
            System.out.println(s);
         }
         else
         {
            String s = "";
            int max2 = Integer.MIN_VALUE;
            for(int x = 0; x < arrayLength; x++)
            {
               array[x] = max - array[x];
               if(array[x] > max2)
                  max2 = array[x];
            }
            for(int x = 0; x < arrayLength; x++)
            {
               array[x] = max2 - array[x];
               s = s + array[x] + " ";
            }
            s.trim();
            System.out.println(s);
         }
         */
         String s = "";
         for(int x = 0; x < arrayLength; x++)
            s = s + array[x] + " ";
         s.trim();
         System.out.println(s);
      }
   }
}


import java.io.*;
import java.awt.Rectangle;
import java.util.*;

public class problemA
{
   public static void main (String[] args) throws IOException
   {
      BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
      //BufferedReader input = new BufferedReader(new FileReader("diamond.in"));
      //PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("diamond.out")));
      StringTokenizer token = new StringTokenizer(input.readLine());
      int maxCount = Integer.parseInt(token.nextToken());
      for(int b = 0; b < maxCount; b++)
      {
         token = new StringTokenizer(input.readLine());
         int arrayLength = Integer.parseInt(token.nextToken());
         int operations = Integer.parseInt(token.nextToken());
         int [] array = new int[arrayLength];
         token = new StringTokenizer(input.readLine());
         int max = 0;
         for(int x = 0; x < arrayLength; x++)
         {
            array[x] = Integer.parseInt(token.nextToken());
            if(array[x] > max)
               max = array[x];
         }
         operations = operations % 2;
         if(operations == 1)
         {
            for(int x = 0; x < arrayLength; x++)
            {
               array[x] = max - array[x];
               System.out.print(array[x] + " ");
            }
            System.out.println();
         }
         else
         {
            int max2 = 0;
            for(int x = 0; x < arrayLength; x++)
            {
               array[x] = max - array[x];
               if(array[x] > max2)
                  max2 = array[x];
            }
            for(int x = 0; x < arrayLength; x++)
            {
               array[x] = max2 - array[x];
               System.out.print(array[x] + " ");
            }
            System.out.println();
         }
      }

   }
}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.time.LocalTime;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Main {

    public static void main(String[] args) {

    	FastScanner scan = new FastScanner();

    	int t = scan.nextInt();
    	for(int tt=0; tt<t; tt++) {
    		int n = scan.nextInt(), k = scan.nextInt();
    		ArrayList<Integer> arr = scan.readArrayList(n);
    		for(int i=0; i<k; i++) {
    			int max = arr.get(0);
    			for(int j=1; j<n; j++) max = Math.max(max, arr.get(j));
    			for(int j=0; j<n; j++) arr.set(j, max-arr.get(j));
    		}
    		for(int i=0; i<n; i++) System.out.print(arr.get(i) + " ");
    		System.out.println();
    	}
    }

    public static void sort(int [] a) {
    	ArrayList<Integer> b = new ArrayList<>();
    	for(int i: a) b.add(i);
    	Collections.sort(b);
    	for(int i=0; i<a.length; i++) a[i]= b.get(i);
    }

    static class FastScanner{

    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st = new StringTokenizer("");
    	String next() {
    		while(!st.hasMoreTokens())
    			try {
    				st = new StringTokenizer(br.readLine());
    			} catch (IOException e){
    				e.printStackTrace();
    			}
    		return st.nextToken();
    	}

    	int nextInt() {
    		return Integer.parseInt(next());
    	}

    	int [] readArray(int n) {
    		int [] a = new int[n];
    		for(int i=0; i<n ; i++) a[i] = nextInt();
    		return a;
    	}

    	ArrayList<Integer> readArrayList(int n) {
    		ArrayList<Integer> a = new ArrayList<>();
    		for(int i=0; i<n; i++) a.add(nextInt());
    		return a;
    	}

    	long nextLong() {
    		return Long.parseLong(next());
    	}

    }

}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.time.LocalTime;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class B {

    public static void main(String[] args) {

    	FastScanner scan = new FastScanner();

    	int t = scan.nextInt();
   	for(int tt=0; tt<t; tt++) {
    		int n = scan.nextInt(), k = scan.nextInt();
    		long [] arr = new long[n];
    		for(int i=0; i<n; i++) arr[i] = scan.nextLong();
    		long max = arr[0];
    		for(int i=1; i<n; i++) max = Math.max(arr[i], max);
    		for(int i=0; i<n; i++) arr[i] = max - arr[i];
    		k--;
    		for(int i=0; i<k%2; i++) {
    			max = arr[0];
    			for(int j=1; j<n; j++) max = Math.max(arr[i], max);
        		for(int j=0; j<n; j++) arr[i] = max - arr[i];
    		}
    		for(int i=0; i<n; i++) System.out.print(arr[i] + " ");
    		System.out.println();
    	}

    }

    public static void sort(int [] a) {
    	ArrayList<Integer> b = new ArrayList<>();
    	for(int i: a) b.add(i);
    	Collections.sort(b);
    	for(int i=0; i<a.length; i++) a[i]= b.get(i);
    }

    static class FastScanner{

    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st = new StringTokenizer("");
    	String next() {
    		while(!st.hasMoreTokens())
    			try {
    				st = new StringTokenizer(br.readLine());
    			} catch (IOException e){
    				e.printStackTrace();
    			}
    		return st.nextToken();
    	}

    	int nextInt() {
    		return Integer.parseInt(next());
    	}

    	int [] readArray(int n) {
    		int [] a = new int[n];
    		for(int i=0; i<n ; i++) a[i] = nextInt();
    		return a;
    	}

    	long nextLong() {
    		return Long.parseLong(next());
    	}

    }

}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.time.LocalTime;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class B {

    public static void main(String[] args) {

    	FastScanner scan = new FastScanner();

    	int t = scan.nextInt();
   	for(int tt=0; tt<t; tt++) {
    		int n = scan.nextInt(), k = scan.nextInt();
    		long [] arr = new long[n];
    		for(int i=0; i<n; i++) arr[i] = scan.nextLong();
    		long max = arr[0];
    		for(int i=1; i<n; i++) max = Math.max(arr[i], max);
    		for(int i=0; i<n; i++) arr[i] = max - arr[i];
    		if(k % 2 == 0) {
    			max = arr[0];
    			for(int j=1; j<n; j++) max = Math.max(arr[j], max);
        		for(int j=0; j<n; j++) arr[j] = max - arr[j];
    		}
    		for(int i=0; i<n; i++) System.out.print(arr[i] + " ");
    		System.out.println();
    	}

    }

    public static void sort(int [] a) {
    	ArrayList<Integer> b = new ArrayList<>();
    	for(int i: a) b.add(i);
    	Collections.sort(b);
    	for(int i=0; i<a.length; i++) a[i]= b.get(i);
    }

    static class FastScanner{

    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st = new StringTokenizer("");
    	String next() {
    		while(!st.hasMoreTokens())
    			try {
    				st = new StringTokenizer(br.readLine());
    			} catch (IOException e){
    				e.printStackTrace();
    			}
    		return st.nextToken();
    	}

    	int nextInt() {
    		return Integer.parseInt(next());
    	}

    	int [] readArray(int n) {
    		int [] a = new int[n];
    		for(int i=0; i<n ; i++) a[i] = nextInt();
    		return a;
    	}

    	long nextLong() {
    		return Long.parseLong(next());
    	}

    }

}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.time.LocalTime;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class B {

    public static void main(String[] args) {

    	FastScanner scan = new FastScanner();

    	int t = scan.nextInt();
   	for(int tt=0; tt<t; tt++) {
    		int n = scan.nextInt(), k = scan.nextInt();
    		long [] arr = new long[n];
    		for(int i=0; i<n; i++) arr[i] = scan.nextLong();
    		long max = arr[0];
    		for(int i=1; i<n; i++) max = Math.max(arr[i], max);
    		for(int i=0; i<n; i++) arr[i] = max - arr[i];
    		k--;
    		for(int i=0; i<k%2; i++) {
    			for(int j=1; j<n; j++) max = Math.max(arr[i], max);
        		for(int j=0; j<n; j++) arr[i] = max - arr[i];
    		}
    		for(int i=0; i<n; i++) System.out.print(arr[i] + " ");
    		System.out.println();
    	}

    }

    public static void sort(int [] a) {
    	ArrayList<Integer> b = new ArrayList<>();
    	for(int i: a) b.add(i);
    	Collections.sort(b);
    	for(int i=0; i<a.length; i++) a[i]= b.get(i);
    }

    static class FastScanner{

    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st = new StringTokenizer("");
    	String next() {
    		while(!st.hasMoreTokens())
    			try {
    				st = new StringTokenizer(br.readLine());
    			} catch (IOException e){
    				e.printStackTrace();
    			}
    		return st.nextToken();
    	}

    	int nextInt() {
    		return Integer.parseInt(next());
    	}

    	int [] readArray(int n) {
    		int [] a = new int[n];
    		for(int i=0; i<n ; i++) a[i] = nextInt();
    		return a;
    	}

    	long nextLong() {
    		return Long.parseLong(next());
    	}

    }

}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.time.LocalTime;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Main {

    public static void main(String[] args) {

    	FastScanner scan = new FastScanner();

    	int t = scan.nextInt();
    	for(int tt=0; tt<t; tt++) {

    		int n = scan.nextInt(); long k = scan.nextLong();
    		long [] arr = new long[n];
    		for(int i=0; i<n; i++) arr[i] = scan.nextLong();

    		int place = 0;
    		long d = arr[0];
    		for(int i=1; i<n; i++) {
    			if(arr[i] > d) {
    				d = arr[i];
    				place = i;
    			}
    		}
    		while(k > 0) {
    				d = arr[place];
    			for(int i=0; i<n; i++) {
    				arr[i] = d - arr[i];
    			}
    			k--;
    		}
    		for(int i=0; i<n; i++) System.out.print(arr[i] + " ");
    		System.out.println();
    	}
    }

    static class FastScanner{

    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st = new StringTokenizer("");
    	String next() {
    		while(!st.hasMoreTokens())
    			try {
    				st = new StringTokenizer(br.readLine());
    			} catch (IOException e){
    				e.printStackTrace();
    			}
    		return st.nextToken();
    	}

    	int nextInt() {
    		return Integer.parseInt(next());
    	}

    	int [] readArray(int n) {
    		int [] a = new int[n];
    		for(int i=0; i<n ; i++) a[i] = nextInt();
    		return a;
    	}

    	long nextLong() {
    		return Long.parseLong(next());
    	}

    }

}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.time.LocalTime;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Main {

    public static void main(String[] args) {

    	FastScanner scan = new FastScanner();

    	int t = scan.nextInt();
    	for(int tt=0; tt<t; tt++) {

    		int n = scan.nextInt(); long k = scan.nextLong();
    		long [] arr = new long[n];
    		for(int i=0; i<n; i++) arr[i] = scan.nextLong();

    		while(k > 0) {
    			long d = arr[0];
    			for(int i=1; i<n; i++) {
    				d = Math.max(d, arr[i]);
    			}
    			for(int i=0; i<n; i++) {
    				arr[i] = d - arr[i];
    			}
    			k--;
    		}
    		for(int i=0; i<n; i++) System.out.print(arr[i] + " ");
    		System.out.println();
    	}
    }

    static class FastScanner{

    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st = new StringTokenizer("");
    	String next() {
    		while(!st.hasMoreTokens())
    			try {
    				st = new StringTokenizer(br.readLine());
    			} catch (IOException e){
    				e.printStackTrace();
    			}
    		return st.nextToken();
    	}

    	int nextInt() {
    		return Integer.parseInt(next());
    	}

    	int [] readArray(int n) {
    		int [] a = new int[n];
    		for(int i=0; i<n ; i++) a[i] = nextInt();
    		return a;
    	}

    	long nextLong() {
    		return Long.parseLong(next());
    	}

    }

}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.time.LocalTime;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class B {

    public static void main(String[] args) {

    	FastScanner scan = new FastScanner();

    	int t = scan.nextInt();
   	for(int tt=0; tt<t; tt++) {
    		long n = scan.nextLong(), k = scan.nextLong();
    		long [] arr = new long[(int) n];
    		for(int i=0; i<n; i++) arr[i] = scan.nextLong();
    		long max = arr[0];
    		for(int i=1; i<n; i++) max = Math.max(arr[i], max);
    		for(int i=0; i<n; i++) arr[i] = max - arr[i];
    		if(k % 2 == 0) {
    			max = arr[0];
    			for(int j=1; j<n; j++) max = Math.max(arr[j], max);
        		for(int j=0; j<n; j++) arr[j] = max - arr[j];
    		}
    		for(int i=0; i<n; i++) System.out.print(arr[i] + " ");
    		System.out.println();
    	}

    }

    public static void sort(int [] a) {
    	ArrayList<Integer> b = new ArrayList<>();
    	for(int i: a) b.add(i);
    	Collections.sort(b);
    	for(int i=0; i<a.length; i++) a[i]= b.get(i);
    }

    static class FastScanner{

    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st = new StringTokenizer("");
    	String next() {
    		while(!st.hasMoreTokens())
    			try {
    				st = new StringTokenizer(br.readLine());
    			} catch (IOException e){
    				e.printStackTrace();
    			}
    		return st.nextToken();
    	}

    	int nextInt() {
    		return Integer.parseInt(next());
    	}

    	int [] readArray(int n) {
    		int [] a = new int[n];
    		for(int i=0; i<n ; i++) a[i] = nextInt();
    		return a;
    	}

    	long nextLong() {
    		return Long.parseLong(next());
    	}

    }

}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n= scan.nextInt();
        for(int i=0;i<n;i++)
        {
            long m = scan.nextInt();
            long k = scan.nextInt();
            long max =0;
            long d=0;
            long []arr= new long[(int)m];
            for(int j=0;j<m;j++){
                arr[j] = scan.nextInt();
                if (max < arr[j])
                {
                    max = arr[j];
                }
            }
            if(k==0)
            {
                for(int j=0;j<m;j++)
                    System.out.print(arr[j]+" ");
                System.out.println();
            }
            else if(k % 2 == 0)
            {
                for(int a=0;a<2;a++){
                    d = max;
                    max=0;
                    for(int b=0;b<m;b++){
                        arr[b] = (d-arr[b]);
                        if(arr[b]>max)
                            max = arr[b];
                    }
                }
                for(int f=0;f<m;f++)
                    System.out.print(arr[f]+" ");
                System.out.println();
            }
            else{
                for(int e=0;e<m;e++)
                    System.out.print(max-arr[e]+" ");
                System.out.println();
            }
        }
    }
}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n= scan.nextInt();
        for(int i=0;i<n;i++)
        {
            int m = scan.nextInt();
            String k = scan.next();
            long max =Integer.MIN_VALUE;
            long d=0;
            long []arr= new long[m];
            for(int j=0;j<m;j++){
                arr[j] = scan.nextInt();
                if (max < arr[j])
                {
                    max = arr[j];
                }
            }
            int a = k.length()-1;
            if(k.charAt(a) == '0'|| k.charAt(a) =='2'||k.charAt(a) == '4'|| k.charAt(a) =='8' || k.charAt(a) =='6')
            {
                for(int l=0;l<2;l++){
                    d = max;
                    max=0;
                    for(int b=0;b<m;b++){
                        arr[b] = (d-arr[b]);
                        if(arr[b]>max)
                            max = arr[b];
                    }
                }
                for(int f=0;f<m;f++)
                    System.out.print(arr[f]+" ");
            }
            else{
                System.out.println(max);
                for(int e=0;e<m;e++)
                    System.out.print(max-arr[e]+" ");
            }
            System.out.println();
        }
    }
}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n= scan.nextInt();
        for(int i=0;i<n;i++)
        {
            int m = scan.nextInt();
            String k = scan.next();
            long max =0;
            long d=0;
            long []arr= new long[m];
            for(int j=0;j<m;j++){
                arr[j] = scan.nextInt();
                if (max < arr[j])
                {
                    max = arr[j];
                }
            }
            int a = k.length()-1;
            if(k.charAt(a) == '0'|| k.charAt(a) =='2'||k.charAt(a) == '4'|| k.charAt(a) =='8')
            {
                for(int l=0;l<2;l++){
                    d = max;
                    max=0;
                    for(int b=0;b<m;b++){
                        arr[b] = (d-arr[b]);
                        if(arr[b]>max)
                            max = arr[b];
                    }
                }
                for(int f=0;f<m;f++)
                    System.out.print(arr[f]+" ");
                System.out.println();
            }
            else{
                for(int e=0;e<m;e++)
                    System.out.print(max-arr[e]+" ");
                System.out.println();
            }
        }
    }
}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n= scan.nextInt();
        for(int i=0;i<n;i++)
        {
            int m = scan.nextInt();
            int k = scan.nextInt();
            int d=0;
            int max=0;
            int []arr = new int[m];
            for(int j=0;j<m;j++) {
                arr[j] = scan.nextInt();
                if (max < arr[j])
                {
                    max = arr[j];
                }
            }
            for(int a=0;a<k;a++){
                d = max;

                for(int b=0;b<m;b++){
                    arr[b] = (d-arr[b]);
                    if(arr[b]>max)
                        max = arr[b];
                }
            }
            for(int c=0;c<m;c++)
                System.out.print(arr[c]+" ");
            System.out.println();
        }
    }
}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n= scan.nextInt();
        for(int i=0;i<n;i++)
        {
            int m = scan.nextInt();
            int k = scan.nextInt();
            int d=0;
            int max=0;
            int []arr = new int[m];
            for(int j=0;j<m;j++) {
                arr[j] = scan.nextInt();
                if (max < arr[j])
                {
                    max = arr[j];
                }
            }
            for(int a=0;a<k;a++){
                d = max;
                max=0;
                for(int b=0;b<m;b++){
                    arr[b] = (d-arr[b]);
                    if(arr[b]>max)
                        max = arr[b];
                }
            }
            for(int c=0;c<m;c++)
                System.out.print(arr[c]+" ");
            System.out.println();
        }
    }
}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n= scan.nextInt();
        for(int i=0;i<n;i++)
        {
            int m = scan.nextInt();
            int k = scan.nextInt();
            long max =0;
            long d=0;
            long []arr= new long[m];
            for(int j=0;j<m;j++){
                arr[j] = scan.nextInt();
                if (max < arr[j])
                {
                    max = arr[j];
                }
            }
            if(k==0)
            {
                for(int j=0;j<m;j++)
                    System.out.print(arr[j]+" ");
                System.out.println();
            }
            else if(k % 2 == 0)
            {
                for(int a=0;a<2;a++){
                    d = max;
                    max=0;
                    for(int b=0;b<m;b++){
                        arr[b] = (d-arr[b]);
                        if(arr[b]>max)
                            max = arr[b];
                    }
                }
                for(int f=0;f<m;f++)
                    System.out.print(arr[f]+" ");
                System.out.println();
            }
            else{
                for(int e=0;e<m;e++)
                    System.out.print(max-arr[e]+" ");
                System.out.println();
            }
        }
    }
}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n= scan.nextInt();
        for(int i=0;i<n;i++)
        {
            int m = scan.nextInt();
            String k = scan.next();
            long max =Integer.MIN_VALUE;
            long d=0;
            long []arr= new long[m];
            for(int j=0;j<m;j++){
                arr[j] = scan.nextInt();
                if (max < arr[j])
                {
                    max = arr[j];
                }
            }
            int a = k.length()-1;
            if(k.charAt(a) == '0'|| k.charAt(a) =='2'||k.charAt(a) == '4'|| k.charAt(a) =='8' || k.charAt(a) =='6')
            {
                for(int l=0;l<2;l++){
                    d = max;
                    max=0;
                    for(int b=0;b<m;b++){
                        arr[b] = (d-arr[b]);
                        if(arr[b]>max)
                            max = arr[b];
                    }
                }
                for(int f=0;f<m;f++)
                    System.out.print(arr[f]+" ");
            }
            else{
                for(int e=0;e<m;e++)
                    System.out.print(max-arr[e]+" ");
            }
            System.out.println();
        }
    }
}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n= scan.nextInt();
        for(int i=0;i<n;i++)
        {
            int m = scan.nextInt();
            String k = scan.next();
            long max =0;
            long d=0;
            long []arr= new long[m];
            for(int j=0;j<m;j++){
                arr[j] = scan.nextInt();
                if (max < arr[j])
                {
                    max = arr[j];
                }
            }
            int a = k.length()-1;
            if(k.charAt(a) == '0'|| k.charAt(a) =='2'||k.charAt(a) == '4'|| k.charAt(a) =='8' || k.charAt(a) =='6')
            {
                for(int l=0;l<2;l++){
                    d = max;
                    max=0;
                    for(int b=0;b<m;b++){
                        arr[b] = (d-arr[b]);
                        if(arr[b]>max)
                            max = arr[b];
                    }
                }
                for(int f=0;f<m;f++)
                    System.out.print(arr[f]+" ");
            }
            else{
                for(int e=0;e<m;e++)
                    System.out.print(max-arr[e]+" ");
            }
            System.out.println();
        }
    }
}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n= scan.nextInt();
        for(int i=0;i<n;i++)
        {
            int m = scan.nextInt();
            String k = scan.next();
            long max =0;
            long d=0;
            long []arr= new long[m];
            for(int j=0;j<m;j++){
                arr[j] = scan.nextInt();
                if (max < arr[j])
                {
                    max = arr[j];
                }
            }
            int a = k.length()-1;
            System.out.println(a);
            if(k.charAt(a) == '0'|| k.charAt(a) =='2'||k.charAt(a) == '4'|| k.charAt(a) =='8' || k.charAt(a) =='6')
            {
                for(int l=0;l<2;l++){
                    d = max;
                    max=0;
                    for(int b=0;b<m;b++){
                        arr[b] = (d-arr[b]);
                        if(arr[b]>max)
                            max = arr[b];
                    }
                }
                for(int f=0;f<m;f++)
                    System.out.print(arr[f]+" ");
            }
            else{
                for(int e=0;e<m;e++)
                    System.out.print(max-arr[e]+" ");
            }
            System.out.println();
        }
    }
}


package com.avi;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n= scan.nextInt();
        for(int i=0;i<n;i++)
        {
            int m = scan.nextInt();
            int k = scan.nextInt();
            int d=0;
            int max=0;
            int []arr = new int[m];
            for(int j=0;j<m;j++) {
                arr[j] = scan.nextInt();
                if (max < arr[j])
                {
                    max = arr[j];
                }
            }
            for(int a=0;a<k;a++){
                d = max;
                max=0;
                for(int b=0;b<m;b++){
                    arr[b] = (d-arr[b]);
                    if(arr[b]>max)
                        max = arr[b];
                }
            }
            for(int c=0;c<m;c++)
                System.out.print(arr[c]+" ");
            System.out.println();
        }
    }
}


package com.avi;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n= scan.nextInt();
        for(int i=0;i<n;i++)
        {
            long m = scan.nextInt();
            long k = scan.nextInt();
            long max =0;
            long d=0;
            long []arr= new long[(int)m];
            for(int j=0;j<m;j++){
                arr[j] = scan.nextInt();
                if (max < arr[j])
                {
                    max = arr[j];
                }
            }
            if(k==0)
            {
                for(int j=0;j<m;j++)
                    System.out.print(arr[j]+" ");
                System.out.println();
            }
            else if(k % 2 == 0)
            {
                for(int a=0;a<2;a++){
                    d = max;
                    max=0;
                    for(int b=0;b<m;b++){
                        arr[b] = (d-arr[b]);
                        if(arr[b]>max)
                            max = arr[b];
                    }
                }
                for(int f=0;f<m;f++)
                    System.out.print(arr[f]+" ");
                System.out.println();
            }
            else{
                for(int e=0;e<m;e++)
                    System.out.print(max-arr[e]+" ");
                System.out.println();
            }
        }
    }
}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n= scan.nextInt();
        for(int i=0;i<n;i++)
        {
            int m = scan.nextInt();
            int k = scan.nextInt();
            int max =0;
            int d=0;
            int []arr= new int[m];
            for(int j=0;j<m;j++){
                arr[j] = scan.nextInt();
                if (max < arr[j])
                {
                    max = arr[j];
                }
            }
            if(k==0)
            {
                for(int j=0;j<m;j++)
                    System.out.print(arr[j]+" ");
                System.out.println();
            }
            else if(k % 2 == 0)
            {
                for(int a=0;a<2;a++){
                    d = max;
                    max=0;
                    for(int b=0;b<m;b++){
                        arr[b] = (d-arr[b]);
                        if(arr[b]>max)
                            max = arr[b];
                    }
                }
                for(int f=0;f<m;f++)
                    System.out.print(arr[f]+" ");
                System.out.println();
            }
            else{
                for(int e=0;e<m;e++)
                    System.out.print(max-arr[e]+" ");
                System.out.println();
            }
        }
    }
}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n= scan.nextInt();
        for(int i=0;i<n;i++)
        {
            int m = scan.nextInt();
            String k = scan.next();
            long max =0;
            long d=0;
            long []arr= new long[m];
            for(int j=0;j<m;j++){
                arr[j] = scan.nextInt();
                if (max < arr[j])
                {
                    max = arr[j];
                }
            }
            int a = k.length()-1;
            if(k.charAt(a) == '0'|| k.charAt(a) =='2'||k.charAt(a) == '4'|| k.charAt(a) =='8')
            {
                for(int a=0;a<2;a++){
                    d = max;
                    max=0;
                    for(int b=0;b<m;b++){
                        arr[b] = (d-arr[b]);
                        if(arr[b]>max)
                            max = arr[b];
                    }
                }
                for(int f=0;f<m;f++)
                    System.out.print(arr[f]+" ");
                System.out.println();
            }
            else{
                for(int e=0;e<m;e++)
                    System.out.print(max-arr[e]+" ");
                System.out.println();
            }
        }
    }
}


import java.io.*;
import java.util.Scanner;
import java.util.*;
public class bad
{
    public static void main(String args[]) throws IOException
    {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int t,n;
        t=Integer.parseInt(reader.readLine());
        for(int i=t;i>0;i--)
        {
            long k;
            n=Integer.parseInt(reader.readLine());
            k=Long.parseLong(reader.readLine());
            long a[]=new long[n];
            for(int j=0;j<n;j++)
            {
                a[j]=Long.parseLong(reader.readLine());
            }
            Arrays.sort(a);
            if(k%2!=0)
            {
                long max=a[n-1];
                for(int j=0;j<n;j++)
                {
                    a[j]=a[j]-max;
                }
            }
            else
            {
                long max=a[n-1];
                for(int j=0;j<n;j++)
                {
                    a[j]=a[j]-max;
                }
                Arrays.sort(a);
                long max1=a[n-1];
                for(int j=0;j<n;j++)
                {
                    a[j]=a[j]-max1;
                }
            }
            for(int j=0;j<n;j++)
            {
                System.out.print(a[j]+" ");
            }
            System.out.println();
        }
    }
}


import java.io.*;
import java.util.Scanner;
import java.util.*;
public class bad
{
    public static void main(String args[]) throws IOException
    {
        Scanner in=new Scanner(System.in);
        int t,n;
        t=in.nextInt();
        for(int i=t;i>0;i--)
        {
            long k;
            n=in.nextInt();
            k=in.nextLong();
            long a[]=new long[n];
            long b[]=new long[n];
            long c[]=new long[n];
            for(int j=0;j<n;j++)
            {
                a[j]=in.nextLong();
            }
            for(int j=0;j<n;j++)
            {
                b[j]=a[j];
            }
            Arrays.sort(b);
            if(k%2!=0)
            {
                long max=b[n-1];
                for(int j=0;j<n;j++)
                {
                    a[j]=max-a[j];
                }
            }
            else
            {
                long max=a[n-1];
                for(int j=0;j<n;j++)
                {
                    a[j]=max-a[j];
                }
                for(int j=0;j<n;j++)
                {
                    c[j]=a[j];
                }
                Arrays.sort(c);
                long max1=c[n-1];
                for(int j=0;j<n;j++)
                {
                    a[j]=max1-a[j];
                }
            }
            for(int j=0;j<n;j++)
            {
                System.out.print(a[j]+" ");
            }
            System.out.println();
        }
    }
}


import java.io.*;
import java.util.Scanner;
import java.util.*;
public class bad
{
    public static void main(String args[]) throws IOException
    {
        Scanner in=new Scanner(System.in);
        int t,n;
        t=in.nextInt();
        for(int i=t;i>0;i--)
        {
            long k;
            n=in.nextInt();
            k=in.nextLong();
            long a[]=new long[n];
            for(int j=0;j<n;j++)
            {
                a[j]=in.nextLong();
            }
            Arrays.sort(a);
            if(k%2!=0)
            {
                long max=a[n-1];
                for(int j=0;j<n;j++)
                {
                    a[j]=a[j]-max;
                }
            }
            else
            {
                long max=a[n-1];
                for(int j=0;j<n;j++)
                {
                    a[j]=a[j]-max;
                }
                Arrays.sort(a);
                long max1=a[n-1];
                for(int j=0;j<n;j++)
                {
                    a[j]=a[j]-max1;
                }
            }
            for(int j=0;j<n;j++)
            {
                System.out.print(a[j]+" ");
            }
            System.out.println();
        }
    }
}


import java.io.*;
import java.util.Scanner;
import java.util.*;
public class bad
{
    public static void main(String args[]) throws IOException
    {
        Scanner in=new Scanner(System.in);
        int t,n;
        t=in.nextInt();
        for(int i=t;i>0;i--)
        {
            long k;
            n=in.nextInt();
            k=in.nextLong();
            long a[]=new long[n];
            for(int j=0;j<n;j++)
            {
                a[j]=in.nextLong();
            }
            Arrays.sort(a);
            if(k%2!=0)
            {
                long max=a[n-1];
                for(int j=0;j<n;j++)
                {
                    a[j]=max-a[j];
                }
            }
            else
            {
                long max=a[n-1];
                for(int j=0;j<n;j++)
                {
                    a[j]=max=a[j];
                }
                Arrays.sort(a);
                long max1=a[n-1];
                for(int j=0;j<n;j++)
                {
                    a[j]=max1-a[j];
                }
            }
            for(int j=0;j<n;j++)
            {
                System.out.print(a[j]+" ");
            }
            System.out.println();
        }
    }
}


import java.util.*;
import java.io.*;
 public class Codechef{
    public static void main(String []args) throws Exception{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   int tc=Integer.parseInt(br.readLine());
   while(tc-->0){
    String str[]=br.readLine().trim().split(" ");
    int n=Integer.parseInt(str[0]);
    long k=Long.parseLong(str[1]);
    String str1[]=br.readLine().trim().split(" ");
    long a1[]=new long[n];
    long a2[]=new long[n];
    long a[]=new long[n];
    long max1=Integer.MIN_VALUE;
    long max2=Integer.MIN_VALUE;
    for(int i=0;i<n;i++) {a[i]=Integer.parseInt(str1[i]);
        max1=Math.max(max1,a[i]);
    }
    for(int i=0;i<n;i++){
        a1[i]=max1-a[i];
        max2=Math.max(max2,a1[i]);
    }
    for(int i=0;i<n;i++){
        a2[i]=max2-a1[i];
    }
    if(k%2==0) {
        for(int i=0;i<n;i++)
        System.out.print(a2[i]+" ");
        System.out.println();
    }
    else{
        for(int i=0;i<n;i++)
        System.out.print(a1[i]+" ");
        System.out.println();
    }
    }
 }
 }


import java.util.*;
import java.io.*;
 public class Codechef{
    public static void main(String []args) throws Exception{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   int tc=Integer.parseInt(br.readLine());
   while(tc-->0){
    String str[]=br.readLine().trim().split(" ");
    int n=Integer.parseInt(str[0]);
    long k=Long.parseLong(str[1]);
    String str1[]=br.readLine().trim().split(" ");
    long a1[]=new long[n];
    long a2[]=new long[n];
    long a[]=new long[n];
    long max1=Integer.MIN_VALUE;
    long max2=Integer.MIN_VALUE;
    for(int i=0;i<n;i++) {a[i]=Integer.parseInt(str1[i]);
        max1=Math.max(max1,a[i]);
    }
    for(int i=0;i<n;i++){
        a1[i]=max1-a[i];
        max2=Math.max(max2,a1[i]);
    }
    for(int i=0;i<n;i++){
        a2[i]=max2-a1[i];
    }
    if(k%2==0) {
        for(int i=0;i<n;i++)
        System.out.print(a2[i]+" ");
        System.out.println();
    }
    else{
        for(int i=0;i<n;i++)
        System.out.print(a2[i]+" ");
        System.out.println();
    }
    }
 }
 }


import java.util.*;
import java.io.*;
 public class Codechef{
    public static void main(String []args) throws Exception{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   int tc=Integer.parseInt(br.readLine());
   while(tc-->0){
    String str[]=br.readLine().trim().split(" ");
    int n=Integer.parseInt(str[0]);
    int k=Integer.parseInt(str[1]);
    String str1[]=br.readLine().trim().split(" ");
    int a1[]=new int[n];
    int a2[]=new int[n];
    int a[]=new int[n];
    int max1=Integer.MIN_VALUE;
    int max2=Integer.MIN_VALUE;
    for(int i=0;i<n;i++) {a[i]=Integer.parseInt(str1[i]);
        max1=Math.max(max1,a[i]);
    }
    for(int i=0;i<n;i++){
        a1[i]=max1-a[i];
        max2=Math.max(max2,a1[i]);
    }
    for(int i=0;i<n;i++){
        a2[i]=max2-a1[i];
    }
    if(k%2==0) {
        for(int i=0;i<n;i++)
        System.out.print(a2[i]+" ");
        System.out.println();
    }
    else{
        for(int i=0;i<n;i++)
        System.out.print(a2[i]+" ");
        System.out.println();
    }
    }
 }
 }


import java.util.*;
import java.io.*;
 public class Codechef{
    public static void main(String []args) throws Exception{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   int tc=Integer.parseInt(br.readLine());
   while(tc-->0){
    String str[]=br.readLine().trim().split(" ");
    int n=Integer.parseInt(str[0]);
    int k=Integer.parseInt(str[1]);
    String str1[]=br.readLine().trim().split(" ");
    int a1[]=new int[n];
    int a2[]=new int[n];
    int a[]=new int[n];
    int max1=Integer.MIN_VALUE;
    int max2=Integer.MIN_VALUE;
    for(int i=0;i<n;i++) {a[i]=Integer.parseInt(str1[i]);
        max1=Math.max(max1,a[i]);
    }
    for(int i=0;i<n;i++){
        a1[i]=max1-a[i];
        max2=Math.max(max2,a1[i]);
    }
    for(int i=0;i<n;i++){
        a2[i]=max2-a1[i];
    }
    if(k%2==0) {
        for(int i=0;i<n;i++)
        System.out.print(a2[i]+" ");
        System.out.println();
    }
    else{
        for(int i=0;i<n;i++)
        System.out.print(a1[i]+" ");
        System.out.println();
    }
    }
 }
 }


//package com.example.codeforcecontest;
import java.util.*;

public class OmkarandInfinityClock {

    public static void helper(long[] a){

        long max=Long.MIN_VALUE;

        for(int i=0;i<a.length;i++) {
            max=Math.max(a[i],max);
        }
        for(int i=0;i<a.length;i++){
            a[i]=max-a[i];
        }
    }

    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        int t=input.nextInt();
        while(t-- >0){
            System.out.println();
            int n=input.nextInt();
            long k=input.nextLong();
            long[] a=new long[n];

            for(int i=0;i<n;i++){
                a[i]=input.nextInt();
            }
            if(k%2!=0){
                helper(a);
            }
            else{
                helper(a);
                helper(a);
            }

            for(int i=0;i<n;i++){
                System.out.print(a[i]+" ");
            }
            System.out.println();

        }
    }
}


//package com.example.codeforcecontest;
import java.util.*;

public class OmkarandInfinityClock {

    public static int[] helper(int[] a){

        int max=Integer.MIN_VALUE;
        for(int i=0;i<a.length;i++) {
            if (a[i] > max)
                max = a[i];
        }

        for(int i=0;i<a.length;i++){
            a[i]=max-a[i];
        }

        return a;

    }

    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        int t=input.nextInt();
        while(t-- >0){
            System.out.println();
            int n=input.nextInt();
            long k=input.nextLong();
            int[] a=new int[n];
            boolean neg=false;

            for(int i=0;i<n;i++){
                a[i]=input.nextInt();
                if(a[i]<0)
                    neg=true;
            }

            if(n==1){
                a[0]=0;
            }
            else{
                if(!neg){       //only nonnegatives
                    if(k%2==1)
                        a=helper(a);
                }
                else{           //has negatives
                    if(k%2==1){
                        a=helper(a);
                    }
                    else{
                        a=helper(a);
                        a=helper(a);
                    }
                }
            }

            for(int i=0;i<n;i++){
                System.out.print(a[i]+" ");
            }

        }
    }
}


//package com.example.codeforcecontest;
import java.util.*;

public class OmkarandInfinityClock {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        int t=input.nextInt();
        while(t-- >0){
            System.out.println();
            int n=input.nextInt();
            long k=input.nextLong();
            int[] a=new int[n];
            for(int i=0;i<n;i++){
                a[i]=input.nextInt();
            }

            while(k-- >0){
                int max=Integer.MIN_VALUE;
                for(int i=0;i<n;i++){
                    if(a[i]>max)
                        max=a[i];
                }
                for(int i=0;i<n;i++){
                    a[i]=max-a[i];
                }
            }

            for(int i=0;i<n;i++){
                System.out.print(a[i]+" ");
            }

        }
    }
}


//package com.example.codeforcecontest;
import java.util.*;

public class OmkarandInfinityClock {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        int t=input.nextInt();
        while(t-- >0){
            System.out.println();
            int n=input.nextInt();
            int k=input.nextInt();
            int[] a=new int[n];
            for(int i=0;i<n;i++){
                a[i]=input.nextInt();
            }

            while(k-- >0){
                int max=Integer.MIN_VALUE;
                for(int i=0;i<n;i++){
                    if(a[i]>max)
                        max=a[i];
                }
                for(int i=0;i<n;i++){
                    a[i]=max-a[i];
                }
            }

            for(int i=0;i<n;i++){
                System.out.print(a[i]+" ");
            }

        }
    }
}


//package com.example.codeforcecontest;
import java.util.*;

public class OmkarandInfinityClock {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        int t=input.nextInt();
        while(t-- >0){
            System.out.println();
            int n=input.nextInt();
            long k=input.nextLong();
            int[] a=new int[n];
            int max=Integer.MIN_VALUE;

            boolean only_pos=true;

            for(int i=0;i<n;i++){
                a[i]=input.nextInt();
                if(a[i]>max)
                    max=a[i];
                if(a[i]<0)
                    only_pos=false;
            }

            if(n==1){
                if(k>=1){
                    a[0]=0;
                }
            }
            else if(k==1){
                for(int i=0;i<n;i++)
                    a[i]=max-a[i];
            }
            else if(only_pos && k%2==1){
                for(int i=0;i<n;i++)
                    a[i]=max-a[i];
            }
            else if(!only_pos){
                if(k%2==0){
                    //perform op twice
                    int new_max=Integer.MIN_VALUE;
                    for(int i=0;i<n;i++) {
                        a[i] = max - a[i];
                        if(a[i]>new_max)
                            new_max=a[i];
                    }

                    for(int i=0;i<n;i++){
                        a[i]=new_max-a[i];
                    }

                }
                else{
                    for(int i=0;i<n;i++)
                        a[i]=max-a[i];
                }
            }

            for(int i=0;i<n;i++){
                System.out.print(a[i]+" ");
            }

        }
    }
}


for _ in range(int(input())):
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    t = [0 for i in range(k)]
    for i in a:
        if i % k > 0:
            t[k - (i % k)] += 1
    ans = 0
    for i in range(k):
        ans = max(ans, (t[i] - 1) * k + i + 1)
    print(ans)


for _ in range(int(input())):
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    t = {}
    ans = 0
    for i in a:
        if i % k > 0:
            t[k - (i % k)] = t.get(k - (i % k), 0) + 1
            ans = max(ans, t[k - (i % k)])
    ansF = 0
    for i in t.keys():
        if t[i] == ans:
            ansF = max(ansF, (t[i] - 1) * k + i + 1)
    print(ansF)


t=int(input())
for _ in range(t):
    n,k=[int(x) for x in input().split()]
    a=[0 for _ in range(k)]
    for x in input().split():
        a[int(x)%k]+=1
    a=(a[1:])[::-1]
    maxa=max(a)
    if maxa==0: print(0); continue
    #print(a)
    lastdex=k-1-a[::-1].index(maxa)
    print(lastdex+1+(maxa-1)*k)


t=int(input())
for _ in range(t):
    n,k=[int(x) for x in input().split()]
    mp={}
    for x in input().split():
        if int(x)%k!=0:
            if int(x)%k in mp:
                mp[int(x)%k]+=1
            else:
                mp[int(x)%k]=1
    if k==1: print(0); continue
    minkey,maxvalue=k,-1
    #print(mp.items())
    for x,y in mp.items():
        if y>maxvalue:
            maxvalue=y
            minkey=x
        elif y==maxvalue:
            minkey=min(x,minkey)
    if maxvalue==-1: print(0); continue
    #print(minkey,maxvalue)
    print(k-minkey+1+(maxvalue-1)*k)


t=int(input())
for _ in range(t):
    n,k=[int(x) for x in input().split()]
    mp={}
    for x in input().split():
        if int(x)%k!=0:
            if int(x)%k in mp:
                mp[int(x)%k]+=1
            else:
                mp[int(x)%k]=1
    if k==1: print(0); continue
    minkey,maxvalue=k,-1
    #print(mp.items())
    for x,y in mp.items():
        if y>=maxvalue:
            maxvalue=y
            minkey=min(x,minkey)
    if maxvalue<=0: print(0); continue
    #print(minkey,maxvalue)
    print(k-minkey+1+(maxvalue-1)*k)


t=int(input())
for _ in range(t):
    n,k=[int(x) for x in input().split()]
    a=[0 for _ in range(k)]
    for x in input().split():
        a[int(x)%k]+=1
    if k==1: print(0); continue
    a=(a[1:])[::-1]
    maxa=max(a)
    if maxa==0: print(0); continue
    #print(a)
    lastdex=k-1-a[::-1].index(maxa)
    print(lastdex+1+(maxa-1)*k)


def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) ]))
def invr():
    return(map(int,input().split()))

n = inp()

for i in range(n):
    l = inlt()
    x = l[0]
    k = l[1]

    l = inlt()
    r = [0] * (k)
    d = {}
    for j in range(x):
        p = l[j] % k
        if(p in d):
            d[p] += 1
        else:
            d[p] = 1

    #print(r)
    repeated = 0
    val = 0
    for j in d:
        if(j == 0):
            continue
        if(d[j] > repeated or (d[j] == repeated and j < val)):
            val = j
            repeated = d[j]

    res = k * repeated
    #print(val, repeated)
    if(val != 0):
        res = res - val + 1
        print(res)
    else:
        print(0)


def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) ]))
def invr():
    return(map(int,input().split()))

n = inp()

for i in range(n):
    l = inlt()
    x = l[0]
    k = l[1]

    l = inlt()
    for j in range(x):
        l[j] = l[j] % k

    l.sort()
    while(len(l)!=0):
        if(l[0] == 0):
            l.pop(0)
        else:
            break
    #print(l)
    repeated = 0
    val = 0
    curr = 0
    if(len(l)!=0):
        prev = l[0]
    for j in range(len(l)):
        if(l[j] == prev):
            curr += 1
        if(curr >= repeated):
            val = prev
            repeated = curr
        if(l[j] != prev):
            prev = l[j]
            curr = 1

    res = k * repeated
    #print(val, repeated)
    if(len(l)):
        res = res - min(l) + 1
        print(res)
    else:
        print(res)


def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) ]))
def invr():
    return(map(int,input().split()))

n = inp()

for i in range(n):
    l = inlt()
    x = l[0]
    k = l[1]

    l = inlt()
    for j in range(x):
        l[j] = l[j] % k

    l.sort()
    while(len(l)!=0):
        if(l[0] == 0):
            l.pop(0)
        else:
            break
    #print(l)
    repeated = 0

    curr = 0
    if(len(l)!=0):
        prev = l[0]
        val = l[0]
    for j in range(len(l)):
        if(l[j] == prev):
            curr += 1
        if(curr > repeated):
            val = prev
            repeated = curr
        if(l[j] != prev):
            prev = l[j]
            curr = 1

    res = k * repeated
    #print(val, repeated)
    if(len(l)):
        res = res - val + 1
        print(res)
    else:
        print(res)


def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) ]))
def invr():
    return(map(int,input().split()))

n = inp()

for i in range(n):
    l = inlt()
    x = l[0]
    k = l[1]

    l = inlt()
    r = [0] * k
    for j in range(x):
        l[j] = l[j] % k
        r[l[j]] += 1

    #print(r)
    repeated = 0
    val = 0
    for j in range(1,len(r)):
        if(r[j] > repeated):
            val = j
            repeated = r[j]

    res = k * repeated
    #print(val, repeated)
    if(val != 0):
        res = res - val + 1
        print(res)
    else:
        print(0)


def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) ]))
def invr():
    return(map(int,input().split()))

n = inp()

for i in range(n):
    l = inlt()
    x = l[0]
    k = l[1]

    l = inlt()
    d = {}
    for j in range(x):
        p = l[j] % k
        if(p in d):
            d[p] += 1
        else:
            d[p] = 1

    #print(r)
    repeated = 0
    val = 0
    for j in d:
        if(j == 0):
            continue
        if(d[j] > repeated or (d[j] == repeated and j < val)):
            val = j
            repeated = d[j]

    res = k * repeated
    #print(val, repeated)
    if(val != 0):
        res = res - val + 1
        print(res)
    else:
        print(0)


def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) ]))
def invr():
    return(map(int,input().split()))

n = inp()

for i in range(n):
    l = inlt()
    x = l[0]
    k = l[1]

    l = inlt()
    r = [0] * (k)
    for j in range(x):
        p = l[j] % k
        r[p] += 1

    #print(r)
    repeated = 0
    val = 0
    for j in range(1,len(r)):
        if(r[j] > repeated):
            val = j
            repeated = r[j]

    res = k * repeated
    #print(val, repeated)
    if(val != 0):
        res = res - val + 1
        print(res)
    else:
        print(0)


production = True

import sys, math, collections

def input(input_format = 0, multi = 0):

    if multi > 0: return [input(input_format) for i in range(multi)]
    else:
        next_line = sys.stdin.readline()[:-1]

        if input_format >= 10:
            use_list = False
            input_format = int(str(input_format)[-1])
        else: use_list = True

        if input_format == 0: formatted_input = [next_line]
        elif input_format == 1: formatted_input = list(map(int, next_line.split()))
        elif input_format == 2: formatted_input = list(map(float, next_line.split()))
        elif input_format == 3: formatted_input = list(next_line)
        elif input_format == 4: formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
        elif input_format == 5: formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
        elif input_format == 6: formatted_input = next_line.split()
        else: formatted_input = [next_line]

        return formatted_input if use_list else formatted_input[0]

def out(output_line, output_format = 0, newline = True):

    formatted_output = ""

    if output_format == 0: formatted_output = str(output_line)
    elif output_format == 1: formatted_output = " ".join(map(str, output_line))
    elif output_format == 2: formatted_output = "\n".join(map(str, output_line))

    print(formatted_output, end = "\n" if newline else "")

def log(*args):
    if not production:
        print("$$$", end = "")
        print(*args)

enum = enumerate

#
#   >>>>>>>>>>>>>>> START OF SOLUTION <<<<<<<<<<<<<<
#

def solve():

    n, k = input(1)
    a = input(1)

    r = [k - (i % k) for i in a]

    r.sort()

    log(a)
    log(r)

    b = set()

    for i in r:
        if i == k:
            continue
        else:
            o = i
            while o in b:
                o += k
            b.add(o)

    log(b)
    if not b:
        out(0)
    else:
        out(max(b) + 1)

    return

for i in range(input(11)): solve()
# solve()

#
#   >>>>>>>>>>>>>>>> END OF SOLUTION <<<<<<<<<<<<<<<
#


production = True

import sys, math, collections

def input(input_format = 0, multi = 0):

    if multi > 0: return [input(input_format) for i in range(multi)]
    else:
        next_line = sys.stdin.readline()[:-1]

        if input_format >= 10:
            use_list = False
            input_format = int(str(input_format)[-1])
        else: use_list = True

        if input_format == 0: formatted_input = [next_line]
        elif input_format == 1: formatted_input = list(map(int, next_line.split()))
        elif input_format == 2: formatted_input = list(map(float, next_line.split()))
        elif input_format == 3: formatted_input = list(next_line)
        elif input_format == 4: formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
        elif input_format == 5: formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
        elif input_format == 6: formatted_input = next_line.split()
        else: formatted_input = [next_line]

        return formatted_input if use_list else formatted_input[0]

def out(output_line, output_format = 0, newline = True):

    formatted_output = ""

    if output_format == 0: formatted_output = str(output_line)
    elif output_format == 1: formatted_output = " ".join(map(str, output_line))
    elif output_format == 2: formatted_output = "\n".join(map(str, output_line))

    print(formatted_output, end = "\n" if newline else "")

def log(*args):
    if not production:
        print("$$$", end = "")
        print(*args)

enum = enumerate

#
#   >>>>>>>>>>>>>>> START OF SOLUTION <<<<<<<<<<<<<<
#

def solve():

    n, k = input(1)
    a = input(1)

    r = [k - (i % k) for i in a]

    r.sort()

    log(a)
    log(r)

    b = dict()

    for i in r:
        b.setdefault(i, 0)

    for i in r:
        if i == k:
            continue
        else:
            o = i + (b[i] * k)
            b[i] += 1

    log(b)

    m = 0
    a = k
    d = True

    for i in r[::-1]:
        if b[i]:
            d = False
        if b[i] > m:
            m = b[i]
            a = i
    log(m, k, a, d)
    if d:
        out(0)
        return
    out((m * k) - (k - a - 1))

    return

for i in range(input(11)): solve()
# solve()

#
#   >>>>>>>>>>>>>>>> END OF SOLUTION <<<<<<<<<<<<<<<
#


production = True

import sys, math, collections

def input(input_format = 0, multi = 0):

    if multi > 0: return [input(input_format) for i in range(multi)]
    else:
        next_line = sys.stdin.readline()[:-1]

        if input_format >= 10:
            use_list = False
            input_format = int(str(input_format)[-1])
        else: use_list = True

        if input_format == 0: formatted_input = [next_line]
        elif input_format == 1: formatted_input = list(map(int, next_line.split()))
        elif input_format == 2: formatted_input = list(map(float, next_line.split()))
        elif input_format == 3: formatted_input = list(next_line)
        elif input_format == 4: formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
        elif input_format == 5: formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
        elif input_format == 6: formatted_input = next_line.split()
        else: formatted_input = [next_line]

        return formatted_input if use_list else formatted_input[0]

def out(output_line, output_format = 0, newline = True):

    formatted_output = ""

    if output_format == 0: formatted_output = str(output_line)
    elif output_format == 1: formatted_output = " ".join(map(str, output_line))
    elif output_format == 2: formatted_output = "\n".join(map(str, output_line))

    print(formatted_output, end = "\n" if newline else "")

def log(*args):
    if not production:
        print("$$$", end = "")
        print(*args)

enum = enumerate

#
#   >>>>>>>>>>>>>>> START OF SOLUTION <<<<<<<<<<<<<<
#

def solve():

    n, k = input(1)
    a = input(1)

    r = [k - (i % k) for i in a]

    r.sort()

    log(a)
    log(r)

    b = [0] * k

    for i in r:
        if i == k:
            continue
        else:
            o = i + (b[i] * k)
            b[i] += 1

    log(b)

    m = 0
    a = k
    d = True

    for i in range(k - 1, 0, -1):
        if b[i]:
            d = False
        if b[i] > m:
            m = b[i]
            a = i
    log(k, a, d)
    if d:
        out(0)
        return
    out((m * k) - (k - a - 1))

    return

for i in range(input(11)): solve()
# solve()

#
#   >>>>>>>>>>>>>>>> END OF SOLUTION <<<<<<<<<<<<<<<
#


production = True

import sys, math, collections

def input(input_format = 0, multi = 0):

    if multi > 0: return [input(input_format) for i in range(multi)]
    else:
        next_line = sys.stdin.readline()[:-1]

        if input_format >= 10:
            use_list = False
            input_format = int(str(input_format)[-1])
        else: use_list = True

        if input_format == 0: formatted_input = [next_line]
        elif input_format == 1: formatted_input = list(map(int, next_line.split()))
        elif input_format == 2: formatted_input = list(map(float, next_line.split()))
        elif input_format == 3: formatted_input = list(next_line)
        elif input_format == 4: formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
        elif input_format == 5: formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
        elif input_format == 6: formatted_input = next_line.split()
        else: formatted_input = [next_line]

        return formatted_input if use_list else formatted_input[0]

def out(output_line, output_format = 0, newline = True):

    formatted_output = ""

    if output_format == 0: formatted_output = str(output_line)
    elif output_format == 1: formatted_output = " ".join(map(str, output_line))
    elif output_format == 2: formatted_output = "\n".join(map(str, output_line))

    print(formatted_output, end = "\n" if newline else "")

def log(*args):
    if not production:
        print("$$$", end = "")
        print(*args)

enum = enumerate

#
#   >>>>>>>>>>>>>>> START OF SOLUTION <<<<<<<<<<<<<<
#

def solve():

    n, k = input(1)
    a = input(1)

    r = [k - (i % k) for i in a]

    r.sort()

    log(a)
    log(r)

    b = [0] * (k + 1)

    for i in r:
        if i == k:
            continue
        else:
            o = i + (b[i] * k)
            b[i] += 1

    log(b)

    m = 0
    a = k
    d = True

    for i in range(k - 1, 0, -1):
        if b[i]:
            d = False
        if b[i] > m:
            m = b[i]
            a = i
    log(k, a, d)
    if d:
        out(0)
        return
    out((m * k) - (k - a - 1))

    return

for i in range(input(11)): solve()
# solve()

#
#   >>>>>>>>>>>>>>>> END OF SOLUTION <<<<<<<<<<<<<<<
#


import heapq as hp
for _ in range(int(input())):
    n,k=map(int,input().split())
    x=0
    a=list(map(int,input().split()))
    heap=[(a[i]//k+1)*k-a[i] for i in range(n) if a[i]%k]
    hp.heapify(heap)
    while heap:
        top=heap[0]
        if top>=x:
            x+=top-x
            hp.heappop(heap)
        else:
            hp.heapreplace(heap,top+k)
            continue
        x+=1
    print(x)


def main():
    for _ in range(int(input())):
        n, k = map(int, input().split())
        a = [(x//k+1)*k-x for x in map(int, input().split()) if x % k]
        a.sort()
        arr=a.copy()
        for i in range(1, len(a)):
            if a[i-1] == a[i]:
                arr[i] = arr[i-1] + k
        x = max(arr)+1 if a else 0
        print(x)

main()


import heapq as hp
for _ in range(int(input())):
    n,k=map(int,input().split())
    count=x=0
    a=list(map(int,input().split()))
    heap=[]
    for i in range(n):
        if a[i]%k==0:
            continue
        diff=(a[i]//k+1)*k-a[i]
        hp.heappush(heap,diff)
    while heap:
        top=hp.heappop(heap)
        if top>=x:
            count+=top-x
            x+=top-x
        else:
            hp.heappush(heap,top+k)
        # in either cases, x & count both will be increased by 1
        # so instead of code duplication, writing only once, below
        x+=1
        count+=1
    print(count)


import heapq as hp
for _ in range(int(input())):
    n,k=map(int,input().split())
    x=0
    a=list(map(int,input().split()))
    heap=[]
    for i in range(n):
        if a[i]%k==0:
            continue
        diff=(a[i]//k+1)*k-a[i]
        hp.heappush(heap,diff)
    while heap:
        top=hp.heappop(heap)
        if top>=x:
            x+=top-x
        else:
            hp.heappush(heap,top+k)
            x-=1
        x+=1
    print(x)


def task_D():
	t = int(input())
	for _ in range(t):
	    n, k = map(int, input().split())
	    array = list(map(int, input().split()))
	    dict_ostatkov = {}
	    sum_ostatkov = 0
	    for curr in array:
	    	ostatok = curr % k
	    	if ostatok != 0:
		    	sum_ostatkov += ostatok
		    	if ostatok not in dict_ostatkov:
    				dict_ostatkov[ostatok] = 1
		    	else:
		    		dict_ostatkov[ostatok] += 1
	    if sum_ostatkov == 0:
	    	print(0)
	    else:
	    	count_max_ostatok = max(dict_ostatkov.values())
	    	max_ostatok = max(dict_ostatkov, key=dict_ostatkov.get)
	    	print(k * count_max_ostatok - max_ostatok + 1)

def main():
    task_D()

if __name__ == '__main__':
    main()


def task_D():
	t = int(input())
	for _ in range(t):
	    n, k = map(int, input().split())
	    array = list(map(int, input().split()))
	    dict_ostatkov = {}
	    sum_ostatkov = 0
	    for curr in array:
	    	ostatok = curr % k
	    	if ostatok != 0:
		    	sum_ostatkov += ostatok
		    	dict_ostatkov[ostatok] += 1
	    if sum_ostatkov == 0:
	    	print(0)
	    else:
	    	count_max_ostatok = max(dict_ostatkov.values())
	    	max_ostatok = max(dict_ostatkov, key=dict_ostatkov.get)
	    	print(k * count_max_ostatok - max_ostatok + 1)

def main():
    task_D()

if __name__ == '__main__':
    main()


def task_D():
	t = int(input())
	for _ in range(t):
	    n, k = map(int, input().split())
	    array = list(map(int, input().split()))
	    dict_ostatkov = {i : 0 for i in range(1, k)}
	    sum_ostatkov = 0
	    for curr in array:
	    	ostatok = curr % k
	    	if ostatok != 0:
		    	sum_ostatkov += ostatok
		    	dict_ostatkov[ostatok] += 1
	    if sum_ostatkov == 0:
	    	print(0)
	    else:
	    	count_max_ostatok = max(dict_ostatkov.values())
	    	max_ostatok = max(dict_ostatkov, key=dict_ostatkov.get)
	    	print(k * count_max_ostatok - max_ostatok + 1)

def main():
    task_D()

if __name__ == '__main__':
    main()


def task_D():
	t = int(input())
	for _ in range(t):
	    n, k = map(int, input().split())
	    array = list(map(int, input().split()))
	    dict_ostatkov = {}
	    sum_ostatkov = 0
	    for curr in array:
	    	ostatok = curr % k
	    	if ostatok != 0:
		    	sum_ostatkov += ostatok
		    	if ostatok not in dict_ostatkov:
    				dict_ostatkov[ostatok] = 1
		    	else:
		    		dict_ostatkov[ostatok] += 1
	    if sum_ostatkov == 0:
	    	print(0)
	    else:
	    	count_max_ostatok = max(dict_ostatkov.values())
	    	max_ostatok = min([key for key in dict_ostatkov.keys() if dict_ostatkov[key] == count_max_ostatok])
	    	#print(count_max_ostatok, max_ostatok)
	    	print(k * count_max_ostatok - max_ostatok + 1)

def main():
    task_D()

if __name__ == '__main__':
    main()


def solve(n, k, a):
    ost = [k - i % k for i in a]
    if ost == [k] * n:
        print(0)
    else:
        d = {}
        x = -1
        maxT = -1
        for i in ost:
            if d.get(i, -1) == -1:
                d[i] = 1
            else:
                d[i] += 1
            if d[i] > maxT:
                x = i
                maxT = d[i]
            elif d[i] == maxT:
                x = max(i, x)
        print(x + k * (maxT-1) + 1)

t = int(input())
while t:
    n, k = map(int, input().split())
    a = [int(i) for i in input().split()]
    solve(n, k, a)
    t -= 1


def solve(n, k, a):
    ost = [k - i % k for i in a]
    if ost == [k] * n:
        print(0)
    else:
        d = {}
        x = -1
        maxT = -1
        for i in ost:
            if i == k:
                continue
            if d.get(i, -1) == -1:
                d[i] = 1
            else:
                d[i] += 1
            if d[i] > maxT:
                x = i
                maxT = d[i]
            elif d[i] == maxT:
                x = max(i, x)
        print(x + k * (maxT-1) + 1)

t = int(input())
while t:
    n, k = map(int, input().split())
    a = [int(i) for i in input().split()]
    solve(n, k, a)
    t -= 1


def solve(n, k, a):
    ost = [k - i % k for i in a]
    if ost == [k] * n:
        print(0)
    else:
        d = {}
        x = -1
        maxT = -1
        for i in ost:
            if d.get(i, -1) == -1:
                d[i] = 1
            else:
                d[i] += 1
            if d[i] > maxT:
                x = i
                maxT = d[i]
        print(x + k * (maxT-1) + 1)

t = int(input())
while t:
    n, k = map(int, input().split())
    a = [int(i) for i in input().split()]
    solve(n, k, a)
    t -= 1


import os
### START FAST IO ###
os_input = os.read(0, int(1e7)).split()
os_input_pos = -1
answer_list = []
def read_s():
  global os_input_pos
  os_input_pos += 1
  return os_input[os_input_pos].decode()
def read_i():
  return int(read_s())
def write_s(v):
  answer_list.append(v)
def write_i(v):
  write_s(str(v))
def print_ans():
  os.write(1, "\n".join(answer_list).encode())
  os.write(1, "\n".encode())
#### END FAST IO ####

from itertools import groupby

T = read_i()
while T:
  T -= 1
  n = read_i()
  k = read_i()
  write_i(
    max(
      [
        k - rem + 1 + k * (len(list(g)) - 1)
        for rem, g in groupby(
          sorted([read_i() % k for i in range(n)])
        )
        if rem != 0
      ],
      default = 0
    )
  )

print_ans()