import java.util.*;

public class ZeroArray {

    public int n;
    public int k;
    public int[] a;

    public ZeroArray(int n, int k, int[] a) {
        this.n = n;
        this.k = k;
        this.a = a;
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();

        for (int i = 0; i < N; i++) {
            int n = scan.nextInt();
            int k = scan.nextInt();
            int[] a = new int[n];
            for (int j = 0; j < n; j++) {
                a[j] = scan.nextInt();
            }
            ZeroArray p = new ZeroArray(n, k, a);
            System.out.println(p.solve());
        }
    }

    public int solve() {

        // Calculate dif array
        int[] dif = new int[n];
        PriorityQueue<Integer> pq = new PriorityQueue<>();

        for (int i = 0; i < dif.length; i++) {
            dif[i] = (a[i] % k) == 0 ? 0 : k - (a[i] % k);
            pq.add(dif[i]);
        }

        int x = 0;
        int numMoves = 0;
        while (!pq.isEmpty()) {
            int nextdif = pq.poll();
            if (nextdif == x) {

                if (nextdif != 0) {

                    numMoves++;
                    x++;

                    Integer skipdif = pq.peek();
                    int m = 1;
                    while (skipdif != null && skipdif == nextdif) {
                        int movedif = pq.poll();
                        pq.add(movedif + m * k);
                        m++;
                        skipdif = pq.peek();
                    }
                }

            } else if (nextdif > x) {

                numMoves += nextdif - x;
                numMoves++;
                x = nextdif + 1;

                Integer skipdif = pq.peek();
                int m = 1;
                while (skipdif != null && skipdif == nextdif) {
                    int movedif = pq.poll();
                    pq.add(movedif + m * k);
                    m++;
                    skipdif = pq.peek();
                }

            }
        }

        return numMoves;
    }
}


import java.util.*;

public class ZeroArray {

    public int n;
    public int k;
    public int[] a;

    public ZeroArray(int n, int k, int[] a) {
        this.n = n;
        this.k = k;
        this.a = a;
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();

        for (int i = 0; i < N; i++) {
            int n = scan.nextInt();
            int k = scan.nextInt();
            int[] a = new int[n];
            for (int j = 0; j < n; j++) {
                a[j] = scan.nextInt();
            }
            ZeroArray p = new ZeroArray(n, k, a);
            System.out.println(p.solve());
        }
    }

    public int solve() {

        // Calculate dif array
        int[] dif = new int[n];
        PriorityQueue<Integer> pq = new PriorityQueue<>();

        for (int i = 0; i < dif.length; i++) {
            dif[i] = (a[i] % k) == 0 ? 0 : k - (a[i] % k);
            pq.add(dif[i]);
        }

        int x = 0;
        int numMoves = 0;
        while (!pq.isEmpty()) {
            int nextdif = pq.poll();
            if (nextdif == x) {

                if (nextdif != 0) {

                    numMoves++;
                    x++;
                }

            } else if (nextdif > x) {

                numMoves += nextdif - x;
                numMoves++;
                x = nextdif + 1;

            }

            Integer skipdif = pq.peek();
            int m = 1;
            while (skipdif != null && skipdif == nextdif) {
                int movedif = pq.poll();
                pq.add(movedif + m * k);
                m++;
                skipdif = pq.peek();
            }
        }

        return numMoves;
    }
}


import java.util.*;

public class ZeroArray {

    public int n;
    public int k;
    public int[] a;

    public ZeroArray(int n, int k, int[] a) {
        this.n = n;
        this.k = k;
        this.a = a;
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();

        for (int i = 0; i < N; i++) {
            int n = scan.nextInt();
            int k = scan.nextInt();
            int[] a = new int[n];
            for (int j = 0; j < n; j++) {
                a[j] = scan.nextInt();
            }
            ZeroArray p = new ZeroArray(n, k, a);
            System.out.println(p.solve());
        }
    }

    public int solve() {

        // Calculate dif array
        int[] dif = new int[n];
        PriorityQueue<Integer> pq = new PriorityQueue<>();

        for (int i = 0; i < dif.length; i++) {
            dif[i] = (a[i] % k) == 0 ? 0 : k - (a[i] % k);
            pq.add(dif[i]);
        }

        int x = 0;
        int numMoves = 0;
        while (!pq.isEmpty()) {
            int nextdif = pq.poll();
            if (nextdif == x) {

                numMoves++;
                x++;

            } else if (nextdif > x) {

                numMoves += nextdif - x;
                numMoves++;
                x = nextdif + 1;

            } else {

                int skipdif = nextdif + k;
                pq.add(skipdif);

            }
        }

        return numMoves;
    }
}


import java.util.*;

public class ZeroArray {

    public int n;
    public int k;
    public int[] a;

    public ZeroArray(int n, int k, int[] a) {
        this.n = n;
        this.k = k;
        this.a = a;
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();

        for (int i = 0; i < N; i++) {
            int n = scan.nextInt();
            int k = scan.nextInt();
            int[] a = new int[n];
            for (int j = 0; j < n; j++) {
                a[j] = scan.nextInt();
            }
            ZeroArray p = new ZeroArray(n, k, a);
            System.out.println(p.solve());
        }
    }

    public long solve() {

        // Calculate dif array
        long[] dif = new long[n];
        PriorityQueue<Long> pq = new PriorityQueue<>();

        for (int i = 0; i < dif.length; i++) {
            dif[i] = (a[i] % k) == 0 ? 0 : k - (a[i] % k);
            pq.add(dif[i]);
        }

        long x = 0;
        long numMoves = 0;
        while (!pq.isEmpty()) {
            long nextdif = pq.poll();
            if (nextdif == x) {

                if (nextdif != 0) {

                    numMoves++;
                    x++;

                    Long skipdif = pq.peek();
                    int m = 1;
                    while (skipdif != null && skipdif == nextdif) {
                        long movedif = pq.poll();
                        pq.add(movedif + m * k);
                        m++;
                        skipdif = pq.peek();
                    }
                }

            } else if (nextdif > x) {

                numMoves += nextdif - x;
                numMoves++;
                x = nextdif + 1;

                Long skipdif = pq.peek();
                int m = 1;
                while (skipdif != null && skipdif == nextdif) {
                    long movedif = pq.poll();
                    pq.add(movedif + m * k);
                    m++;
                    skipdif = pq.peek();
                }

            }
        }

        return numMoves;
    }
}


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

public class Main{

    public static void main(String commandLineArgument[]){

        FS input = new FS();
        PrintWriter out = new PrintWriter(System.out);
        int tc = input.nextInt();
        while(tc --> 0){
            int n = input.nextInt();
            long k = input.nextLong();
            List<Long> a = new ArrayList<>();
            for(int i = 0; i < n; ++i){
                a.add(input.nextLong());
            }
            Collections.sort(a);
            Map<Long , Boolean> highestStep = new TreeMap<>();
            Map<Long, Long> sameTracker = new TreeMap<>();
            long maxValue = 0;
            for(int i = 0; i < n; ++i){
                long value = a.get(i);
                if(value % k != 0){
                    Long curNext = sameTracker.get(value);
                    if(curNext == null){
                        curNext = ((long)Math.ceil((double)value/(double)k)) * k;
                    }
                    long req = curNext - value;
                    while(highestStep.containsKey(req)){
                        curNext += k;
                        req = curNext - value;
                    }
                    highestStep.put(req , true);
                    sameTracker.put(value , curNext);
                    maxValue = Math.max(maxValue , req);
                }
            }
            if(maxValue != 0){
                ++maxValue;
            }
            out.println(maxValue);
        }
        out.close();
    }
}
class FS{
    BufferedReader br;
    StringTokenizer st;
    public FS() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    String next() {
        while(st == null || !st.hasMoreElements()) {
            try {st = new StringTokenizer(br.readLine());}
            catch(Exception e) { throw null;}
        }
        return st.nextToken();
    }
    int nextInt() { return Integer.parseInt(next());}
    double nextDouble() { return Double.parseDouble(next());}
    long nextLong() { return Long.parseLong(next());}
    int[] NIA(int n) {
        int r[] = new int[n];
        for(int i = 0; i < n; i++) r[i] = nextInt();
        return r;
    }
    long[] NLA(int n) {
        long r[] = new long[n];
        for(int i = 0; i < n; i++) r[i] = nextLong();
        return r;
    }
    char[][] grid(int r, int c){
        char res[][] = new char[r][c];
        for(int i = 0; i < r; i++) {
            char l[] = next().toCharArray();
            for(int j = 0; j < c; j++) {
                res[i][j] = l[j];
            }
        }
        return res;
    }
}


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

public class Main{

    public static void main(String commandLineArgument[]){

        FS input = new FS();
        PrintWriter out = new PrintWriter(System.out);
        int tc = input.nextInt();
        while(tc --> 0){
            int n = input.nextInt();
            long k = input.nextLong();
            List<Long> a = new ArrayList<>();
            for(int i = 0; i < n; ++i){
                a.add(input.nextLong());
            }
            Collections.sort(a);
            Map<Long , Boolean> highestStep = new TreeMap<>();
            Map<Long, Long> sameTracker = new TreeMap<>();
            long maxValue = 0;
            for(int i = 0; i < n; ++i){
                long value = a.get(i);
                if(value % k != 0){
                    Long curNext = sameTracker.get(value);
                    if(curNext == null){
                        curNext = ((long)Math.ceil((double)value/(double)k)) * k;
                    }
                    long req = curNext - value;
                    if(highestStep.containsKey(req){
                        curNext += k;
                        req = curNext - value;
                    }
                    highestStep.put(req , true);
                    sameTracker.put(value , curNext);
                    maxValue = Math.max(maxValue , req);
                }
            }
            if(maxValue != 0){
                ++maxValue;
            }
            out.println(maxValue);
        }
        out.close();
    }
}
class FS{
    BufferedReader br;
    StringTokenizer st;
    public FS() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    String next() {
        while(st == null || !st.hasMoreElements()) {
            try {st = new StringTokenizer(br.readLine());}
            catch(Exception e) { throw null;}
        }
        return st.nextToken();
    }
    int nextInt() { return Integer.parseInt(next());}
    double nextDouble() { return Double.parseDouble(next());}
    long nextLong() { return Long.parseLong(next());}
    int[] NIA(int n) {
        int r[] = new int[n];
        for(int i = 0; i < n; i++) r[i] = nextInt();
        return r;
    }
    long[] NLA(int n) {
        long r[] = new long[n];
        for(int i = 0; i < n; i++) r[i] = nextLong();
        return r;
    }
    char[][] grid(int r, int c){
        char res[][] = new char[r][c];
        for(int i = 0; i < r; i++) {
            char l[] = next().toCharArray();
            for(int j = 0; j < c; j++) {
                res[i][j] = l[j];
            }
        }
        return res;
    }
}


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

public class Main{

    public static void main(String commandLineArgument[]){

        FS input = new FS();
        PrintWriter out = new PrintWriter(System.out);
        int tc = input.nextInt();
        while(tc --> 0){
            int n = input.nextInt();
            long k = input.nextLong();
            List<Long> a = new ArrayList<>();
            for(int i = 0; i < n; ++i){
                a.add(input.nextLong());
            }
            Collections.sort(a);
            Map<Long , Boolean> highestStep = new TreeMap<>();
            Map<Long, Long> sameTracker = new TreeMap<>();
            long maxValue = 0;
            for(int i = 0; i < n; ++i){
                long value = a.get(i);
                if(value % k != 0){
                    Long curNext = sameTracker.get(value);
                    if(curNext == null){
                        curNext = ((long)Math.ceil((double)value/(double)k)) * k;
                    }
                    long req = curNext - value;
                    if(highestStep.containsKey(req)){
                        curNext += k;
                        req = curNext - value;
                    }
                    highestStep.put(req , true);
                    sameTracker.put(value , curNext);
                    maxValue = Math.max(maxValue , req);
                }
            }
            if(maxValue != 0){
                ++maxValue;
            }
            out.println(maxValue);
        }
        out.close();
    }
}
class FS{
    BufferedReader br;
    StringTokenizer st;
    public FS() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    String next() {
        while(st == null || !st.hasMoreElements()) {
            try {st = new StringTokenizer(br.readLine());}
            catch(Exception e) { throw null;}
        }
        return st.nextToken();
    }
    int nextInt() { return Integer.parseInt(next());}
    double nextDouble() { return Double.parseDouble(next());}
    long nextLong() { return Long.parseLong(next());}
    int[] NIA(int n) {
        int r[] = new int[n];
        for(int i = 0; i < n; i++) r[i] = nextInt();
        return r;
    }
    long[] NLA(int n) {
        long r[] = new long[n];
        for(int i = 0; i < n; i++) r[i] = nextLong();
        return r;
    }
    char[][] grid(int r, int c){
        char res[][] = new char[r][c];
        for(int i = 0; i < r; i++) {
            char l[] = next().toCharArray();
            for(int j = 0; j < c; j++) {
                res[i][j] = l[j];
            }
        }
        return res;
    }
}


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

public class Main{

    public static void main(String commandLineArgument[]){

        FS input = new FS();
        PrintWriter out = new PrintWriter(System.out);
        int tc = input.nextInt();
        while(tc --> 0){
            int n = input.nextInt();
            long k = input.nextLong();
            List<Long> a = new ArrayList<>();
            for(int i = 0; i < n; ++i){
                a.add(input.nextLong() % k);
            }
            Map<Long, Long> sameTracker = new TreeMap<>();
            long maxValue = 0;
            for(int i = 0; i < n; ++i){
                long value = a.get(i);
                if(value != 0){
                    Long curNext = sameTracker.getOrDefault(value , 0l);
                    ++curNext;
                    sameTracker.put(value , curNext);
                    maxValue = Math.max(maxValue , (curNext * k) - value);
                }
            }
            if(maxValue != 0){
                ++maxValue;
            }
            out.println(maxValue);
        }
        out.close();
    }
}
class FS{
    BufferedReader br;
    StringTokenizer st;
    public FS() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    String next() {
        while(st == null || !st.hasMoreElements()) {
            try {st = new StringTokenizer(br.readLine());}
            catch(Exception e) { throw null;}
        }
        return st.nextToken();
    }
    int nextInt() { return Integer.parseInt(next());}
    double nextDouble() { return Double.parseDouble(next());}
    long nextLong() { return Long.parseLong(next());}
    int[] NIA(int n) {
        int r[] = new int[n];
        for(int i = 0; i < n; i++) r[i] = nextInt();
        return r;
    }
    long[] NLA(int n) {
        long r[] = new long[n];
        for(int i = 0; i < n; i++) r[i] = nextLong();
        return r;
    }
    char[][] grid(int r, int c){
        char res[][] = new char[r][c];
        for(int i = 0; i < r; i++) {
            char l[] = next().toCharArray();
            for(int j = 0; j < c; j++) {
                res[i][j] = l[j];
            }
        }
        return res;
    }
}


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

public class Main{

    public static void main(String commandLineArgument[]){

        FS input = new FS();
        PrintWriter out = new PrintWriter(System.out);
        int tc = input.nextInt();
        while(tc --> 0){
            int n = input.nextInt();
            long k = input.nextLong();
            List<Long> a = new ArrayList<>();
            for(int i = 0; i < n; ++i){
                a.add(input.nextLong() % k);
            }
            Collections.sort(a);
            Map<Long, Long> sameTracker = new TreeMap<>();
            long maxValue = 0;
            for(int i = 0; i < n; ++i){
                long value = a.get(i);
                if(value != 0){
                    Long curNext = sameTracker.getOrDefault(value , 0);
                    ++curNext;
                    sameTracker.put(value , curNext);
                    maxValue = Math.max(maxValue , (curNext * k) - value);
                }
            }
            if(maxValue != 0){
                ++maxValue;
            }
            out.println(maxValue);
        }
        out.close();
    }
}
class FS{
    BufferedReader br;
    StringTokenizer st;
    public FS() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    String next() {
        while(st == null || !st.hasMoreElements()) {
            try {st = new StringTokenizer(br.readLine());}
            catch(Exception e) { throw null;}
        }
        return st.nextToken();
    }
    int nextInt() { return Integer.parseInt(next());}
    double nextDouble() { return Double.parseDouble(next());}
    long nextLong() { return Long.parseLong(next());}
    int[] NIA(int n) {
        int r[] = new int[n];
        for(int i = 0; i < n; i++) r[i] = nextInt();
        return r;
    }
    long[] NLA(int n) {
        long r[] = new long[n];
        for(int i = 0; i < n; i++) r[i] = nextLong();
        return r;
    }
    char[][] grid(int r, int c){
        char res[][] = new char[r][c];
        for(int i = 0; i < r; i++) {
            char l[] = next().toCharArray();
            for(int j = 0; j < c; j++) {
                res[i][j] = l[j];
            }
        }
        return res;
    }
}


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

public class Main{

    public static void main(String commandLineArgument[]){

        FS input = new FS();
        PrintWriter out = new PrintWriter(System.out);
        int tc = input.nextInt();
        while(tc --> 0){
            int n = input.nextInt();
            long k = input.nextLong();
            List<Long> a = new ArrayList<>();
            for(int i = 0; i < n; ++i){
                a.add(input.nextLong());
            }

            Map<Long , Boolean> highestStep = new TreeMap<>();
            Map<Long, Long> sameTracker = new TreeMap<>();
            long maxValue = 0;
            for(int i = 0; i < n; ++i){
                long value = a.get(i);
                if(value % k != 0){
                    Long curNext = sameTracker.get(value);
                    if(curNext == null){
                        curNext = ((long)Math.ceil((double)value/(double)k)) * k;
                    }
                    long req = curNext - value;
                    while(highestStep.containsKey(req)){
                        curNext += k;
                        req = curNext - value;
                    }
                    highestStep.put(req , true);
                    sameTracker.put(value , curNext);
                    maxValue = Math.max(maxValue , req);
                }
            }
            if(maxValue != 0){
                ++maxValue;
            }
            out.println(maxValue);
        }
        out.close();
    }
}
class FS{
    BufferedReader br;
    StringTokenizer st;
    public FS() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    String next() {
        while(st == null || !st.hasMoreElements()) {
            try {st = new StringTokenizer(br.readLine());}
            catch(Exception e) { throw null;}
        }
        return st.nextToken();
    }
    int nextInt() { return Integer.parseInt(next());}
    double nextDouble() { return Double.parseDouble(next());}
    long nextLong() { return Long.parseLong(next());}
    int[] NIA(int n) {
        int r[] = new int[n];
        for(int i = 0; i < n; i++) r[i] = nextInt();
        return r;
    }
    long[] NLA(int n) {
        long r[] = new long[n];
        for(int i = 0; i < n; i++) r[i] = nextLong();
        return r;
    }
    char[][] grid(int r, int c){
        char res[][] = new char[r][c];
        for(int i = 0; i < r; i++) {
            char l[] = next().toCharArray();
            for(int j = 0; j < c; j++) {
                res[i][j] = l[j];
            }
        }
        return res;
    }
}


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

public class Main{

    public static void main(String commandLineArgument[]){

        FS input = new FS();
        PrintWriter out = new PrintWriter(System.out);
        int tc = input.nextInt();
        while(tc --> 0){
            int n = input.nextInt();
            long k = input.nextLong();
            List<Long> a = new ArrayList<>();
            for(int i = 0; i < n; ++i){
                a.add(input.nextLong() % k);
            }
            Collections.sort(a);
            Map<Long, Long> sameTracker = new TreeMap<>();
            long maxValue = 0;
            for(int i = 0; i < n; ++i){
                long value = a.get(i);
                if(value != 0){
                    Long curNext = sameTracker.getOrDefault(value , 0l);
                    ++curNext;
                    sameTracker.put(value , curNext);
                    maxValue = Math.max(maxValue , (curNext * k) - value);
                }
            }
            if(maxValue != 0){
                ++maxValue;
            }
            out.println(maxValue);
        }
        out.close();
    }
}
class FS{
    BufferedReader br;
    StringTokenizer st;
    public FS() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    String next() {
        while(st == null || !st.hasMoreElements()) {
            try {st = new StringTokenizer(br.readLine());}
            catch(Exception e) { throw null;}
        }
        return st.nextToken();
    }
    int nextInt() { return Integer.parseInt(next());}
    double nextDouble() { return Double.parseDouble(next());}
    long nextLong() { return Long.parseLong(next());}
    int[] NIA(int n) {
        int r[] = new int[n];
        for(int i = 0; i < n; i++) r[i] = nextInt();
        return r;
    }
    long[] NLA(int n) {
        long r[] = new long[n];
        for(int i = 0; i < n; i++) r[i] = nextLong();
        return r;
    }
    char[][] grid(int r, int c){
        char res[][] = new char[r][c];
        for(int i = 0; i < r; i++) {
            char l[] = next().toCharArray();
            for(int j = 0; j < c; j++) {
                res[i][j] = l[j];
            }
        }
        return res;
    }
}


import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class stone {
    public static void main(String args[]) throws IOException {
        FastReader sc = new FastReader();
        BufferedWriter w = new BufferedWriter(new PrintWriter(System.out));
        int t=sc.nextInt();
        for(int i=0;i<t;i++) {
            int n = sc.nextInt();
            long k = sc.nextLong();
            long a[] = new long[n];
            //long b[] = new long[(int)k];
            TreeMap <Long,Long> b1=new TreeMap();
            long moves = 0;
            long min=Long.MAX_VALUE;
            for (int j = 0; j < n; j++)
            {
                a[j] = sc.nextLong();
                long rem = a[j] % k;
                if(rem==0)
                {
                    if(b1.containsKey((long)0))
                    b1.put((long)0,b1.get((long)0)+1);
                    else
                        b1.put((long)0,(long)1);
                }
                else if(b1.containsKey(k-rem))
                {
                    b1.put(k-rem,b1.get(k-rem)+1);
                }
                else
                {
                    b1.put(k-rem,(long)1);
                }
            }
           // w.write(b1+"\n");
            if(b1.size()==1&&b1.containsKey((long)0))
            {
                moves=0;
            }
            else {
                boolean flag = false;
                for (long x = 0; !flag; ) {
                    // System.out.println("X: "+x+" moves "+moves);
                    //System.out.println(b1);
                    if (b1.size() > 0) {
                        if (x!=0&&b1.containsKey(x))
                        {
                            if (b1.get(x) > 1)
                            {
                                moves++;
                                b1.put(x + k, b1.get(x) - 1);
                                b1.remove(x);
                                x++;
                            } else if (b1.get(x) == 1)
                            {
                                moves++;
                                b1.remove(x);
                                x++;
                            }
                        }
                        else
                        {
                            if(x==0)
                            {
                                b1.remove((long)0);
                            }
                            moves+=b1.firstKey()-x;
                            x=b1.firstKey();
                            continue;
                        }
                    } else {
                        flag = true;
                    }
                }
            }
            w.write(moves+"\n");
        }
        w.close();
    }
}

class FastReader
{
    BufferedReader br;
    StringTokenizer st;

    public FastReader() throws IOException {
        br = new BufferedReader(new
                InputStreamReader(System.in));

    }

    String next() throws NumberFormatException,IOException,NullPointerException
    {
        while (st == null || !st.hasMoreElements())
        {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt()throws NumberFormatException,IOException,NullPointerException
    {
        return Integer.parseInt(next());
    }

    long nextLong()throws NumberFormatException,IOException,NullPointerException
    {
        return Long.parseLong(next());
    }

    double nextDouble()throws NumberFormatException,IOException,NullPointerException
    {
        return Double.parseDouble(next());
    }

    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}


import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class stone {
    public static void main(String args[]) throws IOException {
        FastReader sc = new FastReader();
        BufferedWriter w = new BufferedWriter(new PrintWriter(System.out));
        int t=sc.nextInt();
        for(int i=0;i<t;i++) {
            int n = sc.nextInt();
            long k = sc.nextLong();
            Long a[] = new Long[n];
            Long b[] = new Long[n];
            long x = 0;
            long moves = 0;
            for (int j = 0; j < n; j++) {
                a[j] = sc.nextLong();
                long rem = a[j] % k;
                if ((a[j] + rem) % k == 0) {
                    if (rem != 0)
                        b[j] = rem;
                    else
                        b[j] = (long) 0;
                } else {
                    b[j] = k - rem;
                }
            }
            Arrays.sort(b);
            boolean flag1=false;
            for(int z=0;z<n;z++)
            {
                if(b[z]!=0)
                {
                  flag1=true;
                  break;
                }
            }
            if(!flag1)
            {
                w.write("0\n");
            }
            if(flag1) {
                System.out.println(Arrays.toString(b));
                boolean flag = false;
                while (!flag) {
                    boolean flag2=false;
                    for (int j = 0; j < n; j++)
                    {
                        flag2=false;
                        if (b[j] == x)
                        {
                            moves++;
                            b[j] -= x;
                            x++;
                            flag2=true;
                        }
                        else if (b[j] == x - 1)
                        {
                            b[j] += k;
                        }
                    }
                    Arrays.sort(b);
                    flag = true;
                    for (int z = 0; z < n; z++)
                    {
                        if (b[z] != 0)
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (!flag2)
                    {
                        x++;
                        moves++;
                    }
                }
                w.write(moves + "\n");
            }
        }
        w.close();
    }
}

class FastReader
{
    BufferedReader br;
    StringTokenizer st;

    public FastReader() throws IOException {
        br = new BufferedReader(new
                InputStreamReader(System.in));

    }

    String next() throws NumberFormatException,IOException,NullPointerException
    {
        while (st == null || !st.hasMoreElements())
        {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt()throws NumberFormatException,IOException,NullPointerException
    {
        return Integer.parseInt(next());
    }

    long nextLong()throws NumberFormatException,IOException,NullPointerException
    {
        return Long.parseLong(next());
    }

    double nextDouble()throws NumberFormatException,IOException,NullPointerException
    {
        return Double.parseDouble(next());
    }

    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}


import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class stone {
    public static void main(String args[]) throws IOException {
        FastReader sc = new FastReader();
        BufferedWriter w = new BufferedWriter(new PrintWriter(System.out));
        int t=sc.nextInt();
        for(int i=0;i<t;i++) {
            int n = sc.nextInt();
            long k = sc.nextLong();
            long a[] = new long[n];
            ArrayList b=new ArrayList<>();
            long x = 0;
            long moves = 0;
            for (int j = 0; j < n; j++)
            {
                a[j] = sc.nextLong();
                long rem = (a[j] % k);
                if ((a[j] + rem) % k == 0)
                {
                    if (rem != 0)
                        b.add(j,rem);
                    else
                        b.add(j,(long)0);
                }
                else
                    {
                    b.add(j,k - rem);
                }
            }
            Collections.sort(b);
           // System.out.println(b);
            boolean flag1=false;
            for(int z=0;z<n;z++)
            {
                if((long)b.get(z)!=(long)0)
                {
                  flag1=true;
                  break;
                }
            }
            if(!flag1)
            {
                w.write("0\n");
            }
            if(flag1) {
                //System.out.println(Arrays.toString(b));
                boolean flag = false;
                while (!flag) {
                   // w.write(b+"\n");
                    boolean flag2=false;
                    for (int j = 0; j < n; j++)
                    {
                        flag2=false;
                        if ((long)b.get(j) == x)
                        {
                            moves++;
                            b.add(j,(long)b.get(j) - x);
                            b.remove(j+1);
                            x++;
                            flag2=true;
                        }
                        else if ((long)b.get(j) == x - 1&&(long)b.get(j)!=0)
                        {
                            b.add(j,(long)b.get(j) +k);
                            b.remove(j+1);
                        }
                    }
                    flag = true;
                    for (int z = 0; z < n; z++)
                    {
                        if ((long)b.get(z) != 0)
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (!flag2)
                    {
                        x++;
                        moves++;
                    }
                }
                w.write(moves + "\n");
            }
        }
        w.close();
    }
}

class FastReader
{
    BufferedReader br;
    StringTokenizer st;

    public FastReader() throws IOException {
        br = new BufferedReader(new
                InputStreamReader(System.in));

    }

    String next() throws NumberFormatException,IOException,NullPointerException
    {
        while (st == null || !st.hasMoreElements())
        {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt()throws NumberFormatException,IOException,NullPointerException
    {
        return Integer.parseInt(next());
    }

    long nextLong()throws NumberFormatException,IOException,NullPointerException
    {
        return Long.parseLong(next());
    }

    double nextDouble()throws NumberFormatException,IOException,NullPointerException
    {
        return Double.parseDouble(next());
    }

    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}


import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class stone {
    public static void main(String args[]) throws IOException {
        FastReader sc = new FastReader();
        BufferedWriter w = new BufferedWriter(new PrintWriter(System.out));
        int t=sc.nextInt();
        for(int i=0;i<t;i++) {
            int n = sc.nextInt();
            long k = sc.nextLong();
            Long a[] = new Long[n];
            Long b[] = new Long[n];
            long x = 0;
            long moves = 0;
            for (int j = 0; j < n; j++)
            {
                a[j] = sc.nextLong();
                long rem = a[j] % k;
                if ((a[j] + rem) % k == 0) {
                    if (rem != 0)
                        b[j] = rem;
                    else
                        b[j] = (long) 0;
                } else {
                    b[j] = k - rem;
                }
            }
            Arrays.sort(b);
            boolean flag1=false;
            for(int z=0;z<n;z++)
            {
                if(b[z]!=0)
                {
                  flag1=true;
                  break;
                }
            }
            if(!flag1)
            {
                w.write("0\n");
            }
            if(flag1) {
                //System.out.println(Arrays.toString(b));
                boolean flag = false;
                while (!flag) {
                    boolean flag2=false;
                    for (int j = 0; j < n; j++)
                    {
                        flag2=false;
                        if (b[j] == x)
                        {
                            moves++;
                            b[j] -= x;
                            x++;
                            flag2=true;
                        }
                        else if (b[j] == x - 1&&b[j]!=0)
                        {
                            b[j] += k;
                        }
                    }
                    Arrays.sort(b);
                    flag = true;
                    for (int z = 0; z < n; z++)
                    {
                        if (b[z] != 0)
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (!flag2)
                    {
                        x++;
                        moves++;
                    }
                }
                w.write(moves + "\n");
            }
        }
        w.close();
    }
}

class FastReader
{
    BufferedReader br;
    StringTokenizer st;

    public FastReader() throws IOException {
        br = new BufferedReader(new
                InputStreamReader(System.in));

    }

    String next() throws NumberFormatException,IOException,NullPointerException
    {
        while (st == null || !st.hasMoreElements())
        {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt()throws NumberFormatException,IOException,NullPointerException
    {
        return Integer.parseInt(next());
    }

    long nextLong()throws NumberFormatException,IOException,NullPointerException
    {
        return Long.parseLong(next());
    }

    double nextDouble()throws NumberFormatException,IOException,NullPointerException
    {
        return Double.parseDouble(next());
    }

    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}


import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class stone {
    public static void main(String args[]) throws IOException {
        FastReader sc = new FastReader();
        BufferedWriter w = new BufferedWriter(new PrintWriter(System.out));
        int t=sc.nextInt();
        for(int i=0;i<t;i++) {
            int n = sc.nextInt();
            long k = sc.nextLong();
            long a[] = new long[n];
            ArrayList b=new ArrayList<>();
            long x = 0;
            long moves = 0;
            for (int j = 0; j < n; j++)
            {
                a[j] = sc.nextLong();
                long rem = (a[j] % k);
                if ((a[j] + rem) % k == 0)
                {
                    if (rem != 0)
                        b.add(j,rem);
                    else
                        b.add(j,(long)0);
                }
                else
                    {
                    b.add(j,k - rem);
                }
            }
            Collections.sort(b);
            System.out.println(b);
            boolean flag1=false;
            for(int z=0;z<n;z++)
            {
                if((long)b.get(z)!=(long)0)
                {
                  flag1=true;
                  break;
                }
            }
            if(!flag1)
            {
                w.write("0\n");
            }
            if(flag1) {
                //System.out.println(Arrays.toString(b));
                boolean flag = false;
                while (!flag) {
                   // w.write(b+"\n");
                    boolean flag2=false;
                    for (int j = 0; j < n; j++)
                    {
                        flag2=false;
                        if ((long)b.get(j) == x)
                        {
                            moves++;
                            b.add(j,(long)b.get(j) - x);
                            b.remove(j+1);
                            x++;
                            flag2=true;
                        }
                        else if ((long)b.get(j) == x - 1&&(long)b.get(j)!=0)
                        {
                            b.add(j,(long)b.get(j) +k);
                            b.remove(j+1);
                        }
                    }
                    flag = true;
                    for (int z = 0; z < n; z++)
                    {
                        if ((long)b.get(z) != 0)
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (!flag2)
                    {
                        x++;
                        moves++;
                    }
                }
                w.write(moves + "\n");
            }
        }
        w.close();
    }
}

class FastReader
{
    BufferedReader br;
    StringTokenizer st;

    public FastReader() throws IOException {
        br = new BufferedReader(new
                InputStreamReader(System.in));

    }

    String next() throws NumberFormatException,IOException,NullPointerException
    {
        while (st == null || !st.hasMoreElements())
        {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt()throws NumberFormatException,IOException,NullPointerException
    {
        return Integer.parseInt(next());
    }

    long nextLong()throws NumberFormatException,IOException,NullPointerException
    {
        return Long.parseLong(next());
    }

    double nextDouble()throws NumberFormatException,IOException,NullPointerException
    {
        return Double.parseDouble(next());
    }

    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}


import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class stone {
    public static void main(String args[]) throws IOException {
        FastReader sc = new FastReader();
        BufferedWriter w = new BufferedWriter(new PrintWriter(System.out));
        int t=sc.nextInt();
        for(int i=0;i<t;i++) {
            int n = sc.nextInt();
            long k = sc.nextLong();
            long a[] = new long[n];
            //long b[] = new long[(int)k];
            TreeMap <Long,Long> b1=new TreeMap();
            long moves = 0;
            long min=Long.MAX_VALUE;
            for (int j = 0; j < n; j++)
            {
                a[j] = sc.nextLong();
                long rem = a[j] % k;
                if(rem==0)
                {
                    if(b1.containsKey((long)0))
                    b1.put((long)0,b1.get((long)0)+1);
                    else
                        b1.put((long)0,(long)1);
                }
                else if(b1.containsKey(k-rem))
                {
                    b1.put(k-rem,b1.get(k-rem)+1);
                }
                else
                {
                    b1.put(k-rem,(long)1);
                }
            }
            if(b1.size()==1&&b1.containsKey((long)0))
            {
                moves=0;
            }
            else {
                boolean flag = false;
                for (long x = 0; !flag; x++) {
                    // System.out.println("X: "+x+" moves "+moves);
                    //System.out.println(b1);
                    if (b1.size() > 0) {
                        if (x!=0&&b1.containsKey(x)) {
                            if (b1.get(x) > 1) {
                                moves++;
                                b1.put(x + k, b1.get(x) - 1);
                                b1.remove(x);
                            } else if (b1.get(x) == 1) {
                                moves++;
                                b1.remove(x);
                            }
                        } else {
                            if(x==0)
                            {
                                b1.remove((long)0);
                            }
                            moves++;
                            continue;
                        }
                    } else {
                        flag = true;
                    }
                }
            }
            w.write(moves+"\n");
        }
        w.close();
    }
}

class FastReader
{
    BufferedReader br;
    StringTokenizer st;

    public FastReader() throws IOException {
        br = new BufferedReader(new
                InputStreamReader(System.in));

    }

    String next() throws NumberFormatException,IOException,NullPointerException
    {
        while (st == null || !st.hasMoreElements())
        {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt()throws NumberFormatException,IOException,NullPointerException
    {
        return Integer.parseInt(next());
    }

    long nextLong()throws NumberFormatException,IOException,NullPointerException
    {
        return Long.parseLong(next());
    }

    double nextDouble()throws NumberFormatException,IOException,NullPointerException
    {
        return Double.parseDouble(next());
    }

    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}


import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class stone {
    public static void main(String args[]) throws IOException {
        FastReader sc = new FastReader();
        BufferedWriter w = new BufferedWriter(new PrintWriter(System.out));
        int t=sc.nextInt();
        for(int i=0;i<t;i++) {
            int n = sc.nextInt();
            long k = sc.nextLong();
            long a[] = new long[n];
            long b[] = new long[n];
            long x = 0;
            long moves = 0;
            long min=Long.MAX_VALUE;
            for (int j = 0; j < n; j++)
            {
                a[j] = sc.nextLong();
                long rem = a[j] % k;
                if ((a[j] + rem) % k == 0) {
                    if (rem != 0)
                        b[j] = rem;
                    else
                        b[j] = (long) 0;
                } else {
                    b[j] = k - rem;
                }
                if(b[j]<min)
                {
                    min=b[j];
                }
            }
            Arrays.sort(b);
            boolean flag1=false;
            for(int z=0;z<n;z++)
            {
                if(b[z]!=0)
                {
                    flag1=true;
                    break;
                }
            }
            if(!flag1)
            {
                w.write("0\n");
            }
            if(flag1) {
                long temp=-1;
                boolean flag = false;
                boolean flag2=false;
                long indmin=-1;
                while (!flag) {
                    //w.write("b: "+Arrays.toString(b)+" moves: "+moves+" x: "+x+" flag2: "+flag2+" temp: "+temp+"\n");
                    if(x==min)
                    {
                        min=Long.MAX_VALUE;
                        for (int j = 0; j < n; j++)
                        {
                            if (temp != x)
                            {
                                flag2 = false;
                                temp = x;
                            }
                            if (b[j] == x)
                            {
                                moves++;
                                b[j] -= x;
                                x++;
                                flag2 = true;
                            }
                            else if (b[j] == x - 1 && b[j] != 0)
                            {
                                b[j] += k;
                                if(j==indmin)
                                {
                                    min=Long.MAX_VALUE;
                                }
                            }
                            if (b[j] < min && b[j] != 0)
                            {
                                min = b[j];
                                indmin=j;
                                //System.out.println("MIN: "+min);
                            }
                        }
                        if (temp != x)
                        {
                            flag2 = false;
                            temp = x;
                        }
                    }
                    //Arrays.sort(b);
                    flag = true;
                    for (int z = 0; z < n; z++)
                    {
                        if (b[z] != 0)
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (!flag2)
                    {
                        x++;
                        moves++;
                    }
                }
                w.write(moves-1 + "\n");
            }
        }
        w.close();
    }
}

class FastReader
{
    BufferedReader br;
    StringTokenizer st;

    public FastReader() throws IOException {
        br = new BufferedReader(new
                InputStreamReader(System.in));

    }

    String next() throws NumberFormatException,IOException,NullPointerException
    {
        while (st == null || !st.hasMoreElements())
        {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt()throws NumberFormatException,IOException,NullPointerException
    {
        return Integer.parseInt(next());
    }

    long nextLong()throws NumberFormatException,IOException,NullPointerException
    {
        return Long.parseLong(next());
    }

    double nextDouble()throws NumberFormatException,IOException,NullPointerException
    {
        return Double.parseDouble(next());
    }

    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}


import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class stone {
    public static void main(String args[]) throws IOException {
        FastReader sc = new FastReader();
        BufferedWriter w = new BufferedWriter(new PrintWriter(System.out));
        int t=sc.nextInt();
        for(int i=0;i<t;i++) {
            int n = sc.nextInt();
            long k = sc.nextLong();
            Long a[] = new Long[n];
            Long b[] = new Long[n];
            long x = 0;
            long moves = 0;
            for (int j = 0; j < n; j++)
            {
                a[j] = sc.nextLong();
                long rem = a[j] % k;
                if ((a[j] + rem) % k == 0) {
                    if (rem != 0)
                        b[j] = rem;
                    else
                        b[j] = (long) 0;
                } else {
                    b[j] = k - rem;
                }
            }
            Arrays.sort(b);
            boolean flag1=false;
            for(int z=0;z<n;z++)
            {
                if(b[z]!=0)
                {
                  flag1=true;
                  break;
                }
            }
            if(!flag1)
            {
                w.write("0\n");
            }
            if(flag1) {
                //System.out.println(Arrays.toString(b));
                boolean flag = false;
                while (!flag) {
                    boolean flag2=false;
                    for (int j = 0; j < n; j++)
                    {
                        flag2=false;
                        if (b[j] == x)
                        {
                            moves++;
                            b[j] -= x;
                            x++;
                            flag2=true;
                        }
                        else if (b[j] == x - 1)
                        {
                            b[j] += k;
                        }
                    }
                    Arrays.sort(b);
                    flag = true;
                    for (int z = 0; z < n; z++)
                    {
                        if (b[z] != 0)
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (!flag2)
                    {
                        x++;
                        moves++;
                    }
                }
                w.write(moves + "\n");
            }
        }
        w.close();
    }
}

class FastReader
{
    BufferedReader br;
    StringTokenizer st;

    public FastReader() throws IOException {
        br = new BufferedReader(new
                InputStreamReader(System.in));

    }

    String next() throws NumberFormatException,IOException,NullPointerException
    {
        while (st == null || !st.hasMoreElements())
        {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt()throws NumberFormatException,IOException,NullPointerException
    {
        return Integer.parseInt(next());
    }

    long nextLong()throws NumberFormatException,IOException,NullPointerException
    {
        return Long.parseLong(next());
    }

    double nextDouble()throws NumberFormatException,IOException,NullPointerException
    {
        return Double.parseDouble(next());
    }

    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}


import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class stone {
    public static void main(String args[]) throws IOException {
        FastReader sc = new FastReader();
        BufferedWriter w = new BufferedWriter(new PrintWriter(System.out));
        int t=sc.nextInt();
        for(int i=0;i<t;i++) {
            int n = sc.nextInt();
            long k = sc.nextLong();
            long a[] = new long[n];
            ArrayList b=new ArrayList<>();
            long x = 0;
            long moves = 0;
            for (int j = 0; j < n; j++)
            {
                a[j] = sc.nextLong();
                long rem = (a[j] % k);
                if ((a[j] + rem) % k == 0)
                {
                    if (rem != 0)
                        b.add(j,rem);
                    else
                        b.add(j,(long)0);
                }
                else
                    {
                    b.add(j,k - rem);
                }
            }
            Collections.sort(b);
            //System.out.println(b);
            boolean flag1=false;
            for(int z=0;z<n;z++)
            {
                if((long)b.get(z)!=(long)0)
                {
                  flag1=true;
                  break;
                }
            }
            if(!flag1)
            {
                w.write("0\n");
            }
            if(flag1) {
                long temp=0;
                boolean flag = false;
                while (!flag) {
                  //  w.write(b+" moves: "+moves+" X: "+x+"\n");
                    boolean flag2=false;
                    for (int j = 0; j < n; j++)
                    {
                        if(temp!=x)
                        {
                            flag2 = false;
                        }
                        if ((long)b.get(j) == x)
                        {
                            moves++;
                            b.add(j,(long)b.get(j) - x);
                            b.remove(j+1);
                            x++;
                            temp=x;
                            flag2=true;
                        }
                        else if ((long)b.get(j) == x - 1&&(long)b.get(j)!=0)
                        {
                            b.add(j,(long)b.get(j) +k);
                            b.remove(j+1);
                        }
                    }
                    flag = true;
                    for (int z = 0; z < n; z++)
                    {
                        if ((long)b.get(z) != 0)
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (!flag2)
                    {
                        x++;
                        moves++;
                      //  w.write("hi\n");
                    }
                }
                w.write(moves + "\n");
            }
        }
        w.close();
    }
}

class FastReader
{
    BufferedReader br;
    StringTokenizer st;

    public FastReader() throws IOException {
        br = new BufferedReader(new
                InputStreamReader(System.in));

    }

    String next() throws NumberFormatException,IOException,NullPointerException
    {
        while (st == null || !st.hasMoreElements())
        {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt()throws NumberFormatException,IOException,NullPointerException
    {
        return Integer.parseInt(next());
    }

    long nextLong()throws NumberFormatException,IOException,NullPointerException
    {
        return Long.parseLong(next());
    }

    double nextDouble()throws NumberFormatException,IOException,NullPointerException
    {
        return Double.parseDouble(next());
    }

    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}


import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
import java.io.InputStreamReader;
import java.io.IOException;

public class codeforces {

	public static void main(String[] args) {

     scanner in  = new scanner();
     int t = in.nextInt();
     for(int i = 0;i<t;i++)
     {
    	 int n = in.nextInt();
    	 int k = in.nextInt();
    	 int[] a = new int[n+1];
    	 int max = 0;
    	 int no = 0;
    	 int[] count = new int[n+1];
    	 for(int j = 1;j<=n;j++)
    	 {
    		 a[j] = in.nextInt();
    		 if(a[j]%k==0)
    			 a[j] = 0;
    		 else
    		 {
    			 a[j] = k-(a[j]%k);
    		 }
    	 }
    	 Arrays.sort(a);
    	for(int j = 1;j<=n;j++)
    	{
    		if(a[j]!=0)
    		{
    		if(a[j]==a[j-1])
    			count[j] = count[j-1]+1;
    		else
    			count[j] = 1;
    		}
    		else
    			count[j] = 0;
    		if(max<=count[j])
    		{
    			max = count[j];
    			no = a[j];
    		}
    	}
    	long ans = no;
    	if(no!=0)
    	   ans = no+(max-1)*k+1;
    		System.out.println(ans);
     }
	}
}
class scanner
{
	BufferedReader br ;
	StringTokenizer st;

	public scanner()
	{
		br = new BufferedReader(new InputStreamReader(System.in));
		st = null;
	}
	 public String next() {
	        while (st == null || !st.hasMoreElements()) {
	            try {
	                st = new StringTokenizer(br.readLine());
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	        }
	        return st.nextToken();
	    }
	public int nextInt()
	{
		return Integer.parseInt(next());
	}
	public long nextLong()
	{
	  return	Long.parseLong(next());
	}
}


import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
import java.io.InputStreamReader;
import java.io.IOException;

public class codeforces {

	public static void main(String[] args) {

     scanner in  = new scanner();
     int t = in.nextInt();
     for(int i = 0;i<t;i++)
     {
    	 int n = in.nextInt();
    	 long k = in.nextInt();
    	 long[] a = new long[n+1];
    	 long max = 0;
    	 long no = 0;
    	 int[] count = new int[n+1];
    	 for(int j = 1;j<=n;j++)
    	 {
    		 a[j] = in.nextInt();
    		 if(a[j]%k==0)
    			 a[j] = 0;
    		 else
    		 {
    			 a[j] = k-(a[j]%k);
    		 }
    	 }
    	 Arrays.sort(a);
    	for(int j = 1;j<=n;j++)
    	{
    		if(a[j]!=0)
    		{
    		if(a[j]==a[j-1])
    			count[j] = count[j-1]+1;
    		else
    			count[j] = 1;
    		}
    		else
    			count[j] = 0;
    		if(max<=count[j])
    		{
    			max = count[j];
    			no = a[j];
    		}
    	}
    	long ans = no;
    	if(no!=0)
    	   ans = no+(max-1)*k+1;
    		System.out.println(ans);

     }
	}
}
class scanner
{
	BufferedReader br ;
	StringTokenizer st;

	public scanner()
	{
		br = new BufferedReader(new InputStreamReader(System.in));
		st = null;
	}
	 public String next() {
	        while (st == null || !st.hasMoreElements()) {
	            try {
	                st = new StringTokenizer(br.readLine());
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	        }
	        return st.nextToken();
	    }
	public int nextInt()
	{
		return Integer.parseInt(next());
	}
	public long nextLong()
	{
	  return	Long.parseLong(next());
	}
}


import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
import java.io.InputStreamReader;
import java.io.IOException;

public class codeforces {

	public static void main(String[] args) {

     scanner in  = new scanner();
     int t = in.nextInt();
     for(int i = 0;i<t;i++)
     {
    	 int n = in.nextInt();
    	 int k = in.nextInt();
    	 int[] a = new int[n+1];
    	 int max = 0;
    	 int no = 0;
    	 int[] count = new int[k];
    	 for(int j = 1;j<=n;j++)
    	 {
    		 a[j] = in.nextInt();
    		 if(a[j]%k==0)
    			 a[j] = 0;
    		 else
    			 a[j] = k-(a[j]%k);
    		 count[a[j]]++;
    	 }
    	 for(int j = 1;j<k;j++)
    	 {
    		 if(count[j]>=max)
    		 {
    			 max = count[j];
    			 no = j;
    		 }
    		// System.out.print(count[j]+" ");
    	 }
    	 System.out.println(no+((max-1)*k)+1);
     }
	}
}
class scanner
{
	BufferedReader br ;
	StringTokenizer st;

	public scanner()
	{
		br = new BufferedReader(new InputStreamReader(System.in));
		st = null;
	}
	 public String next() {
	        while (st == null || !st.hasMoreElements()) {
	            try {
	                st = new StringTokenizer(br.readLine());
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	        }
	        return st.nextToken();
	    }
	public int nextInt()
	{
		return Integer.parseInt(next());
	}
	public long nextLong()
	{
	  return	Long.parseLong(next());
	}
}


import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
import java.io.InputStreamReader;
import java.io.IOException;

public class codeforces {

	public static void main(String[] args) {

     scanner in  = new scanner();
     int t = in.nextInt();
     for(int i = 0;i<t;i++)
     {
    	 int n = in.nextInt();
    	 int k = in.nextInt();
    	 int[] a = new int[n+1];
    	 int max = 0;
    	 int no = 0;
    	 int[] count = new int[n+1];
    	 for(int j = 1;j<=n;j++)
    	 {
    		 a[j] = in.nextInt();
    		 if(a[j]%k==0)
    			 a[j] = 0;
    		 else
    		 {
    			 a[j] = k-(a[j]%k);
    		 }
    	 }
    	 Arrays.sort(a);
    	for(int j = 1;j<=n;j++)
    	{
    		if(a[j]!=0)
    		{
    		if(a[j]==a[j-1])
    			count[j] = count[j-1]+1;
    		else
    			count[j] = 1;
    		}
    		else
    			count[j] = 0;
    		if(max<=count[j])
    		{
    			max = count[j];
    			no = a[j];
    		}
    	}
    	if(no!=0)
    	 System.out.println(no+((max-1)*k)+1);
    	else
    		System.out.println(0);
     }
	}
}
class scanner
{
	BufferedReader br ;
	StringTokenizer st;

	public scanner()
	{
		br = new BufferedReader(new InputStreamReader(System.in));
		st = null;
	}
	 public String next() {
	        while (st == null || !st.hasMoreElements()) {
	            try {
	                st = new StringTokenizer(br.readLine());
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	        }
	        return st.nextToken();
	    }
	public int nextInt()
	{
		return Integer.parseInt(next());
	}
	public long nextLong()
	{
	  return	Long.parseLong(next());
	}
}


import java.util.*;
import java.io.*;
public class Codeforces5 {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

		int t=Integer.parseInt(br.readLine());
		while(t--!=0) {
			String s[]=br.readLine().split(" ");
			int n=Integer.parseInt(s[0]);
			int k=Integer.parseInt(s[1]);
			String st[]=br.readLine().split(" ");
			ArrayList<Integer> ar=new ArrayList<>();

			for(int i=0;i<n;i++) {
				int p=(Integer.parseInt(st[i]));
				if(p % k !=0) ar.add(p);
			}
			if(ar.size()==0) System.out.println(0);

			else {

				int count=1;
				int x=1;
				while(ar.size()!=0) {
					if(ar.size()==1 && ar.get(0) % k==0) {
						count+=0;
						break;
					}
					boolean flag=false;
					for(int i=0;i<ar.size();i++) {
						if((ar.get(i) + x) % k==0) {
							count++;
							x++;
							ar.remove(i);
							flag=true;
							break;
						}

					}
					if(!flag) {
						count++;
						x++;
					}
				}
				System.out.println(count);
			}

		}

	}
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class CodeForcesZeroRemainderArray {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(br.readLine());
		while(t--!=0) {

			String s[]=br.readLine().split(" ");
			int n=Integer.parseInt(s[0]);
			long k=Long.parseLong(s[1]);
			String st[]=br.readLine().split(" ");
			HashMap<Long,Long> hm= new HashMap<>();
			Long count;
			long ans=0;
			for(int i=0;i<n;i++) {
				long x=Long.parseLong(st[i]);
				if(x % k==0) continue;
				long key= (k-(x % k));
				if(hm.containsKey(key)) {
					count=hm.get(key);
					count++;
					hm.replace(key, count);
				}
				else hm.put(key,(long) 1);
				key=(int) (k*(hm.get(key)-1))+key;
				ans=Math.max(ans, key+1);
			}
			System.out.println(ans);
		}

	}

}


package gfg;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class CodeForcesZeroRemainderArray {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(br.readLine());
		while(t--!=0) {

			String s[]=br.readLine().split(" ");
			int n=Integer.parseInt(s[0]);
			long k1=Long.parseLong(s[1]);
			BigInteger k=new BigInteger(s[1]);
			String st[]=br.readLine().split(" ");
			HashMap<BigInteger,BigInteger> hm= new HashMap<>();
			BigInteger count;
			BigInteger  one=new BigInteger("1");
			BigInteger  ans=new BigInteger("0");
			for(int i=0;i<n;i++) {
				long x=Long.parseLong(st[i]);
				if(x % k1==0) continue;
				long ke= (k1-(x % k1));
				String bs=""; bs+=ke;
				BigInteger key=new BigInteger(bs);
				//System.out.println(key+" "+ke);
				if(hm.containsKey(key)) {
					count=hm.get(key);
					count=count.add(one);
					hm.replace(key, count);
				}

				else hm.put(key, one);
				BigInteger val=hm.get(key).subtract(one);
				val=val.multiply(k);
				key=(val.add(key));

				if(key.add(one).compareTo(ans)==1) ans=key.add(one);
			}
			System.out.println(ans);
		}

	}

}


import java.util.*;
import java.io.*;
public class CodeForcesZeroRemainderArray {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(br.readLine());
		while(t--!=0) {

			String s[]=br.readLine().split(" ");
			int n=Integer.parseInt(s[0]);
			long k=Long.parseLong(s[1]);
			String st[]=br.readLine().split(" ");
			HashMap<Integer,Integer> hm= new HashMap<>();
			int count;
			long ans=0;
			for(int i=0;i<n;i++) {
				long x=Long.parseLong(st[i]);
				if(x % k==0) continue;
				int key=(int) (k-(x % k));
				if(hm.containsKey(key)) {
					count=hm.get(key);
					count++;
					hm.replace(key, count);
				}
				else hm.put(key,1);
				key=(int) (k*(hm.get(key)-1))+key;
				ans=Math.max(ans, key+1);
			}
			System.out.println(ans);
		}

	}

}


import java.util.*;
import java.io.*;
public class CodeForcesZeroRemainderArray {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(br.readLine());
		while(t--!=0) {

			String s[]=br.readLine().split(" ");
			int n=Integer.parseInt(s[0]);
			long k=Long.parseLong(s[1]);
			String st[]=br.readLine().split(" ");
			HashMap<Integer,Integer> hm= new HashMap<>();
			int count;
			int maxcount=1; int maxkey=0; int var=0;
			for(int i=0;i<n;i++) {
				long x=Long.parseLong(st[i]);
				long a1=k-(x % k);
				int a=0;
				if(a1 % k!=0 & k!=a1  ) {
					a=(int)a1;
				}
				if(hm.containsKey(a)) {
					count=hm.get(a);
					count++;
					if(maxcount<count) {
						maxcount=count;
						maxkey=a;
					}
					hm.replace(a, count);
				}
				else {
					if(a!=0)
					hm.put(a,1);
				}
				if(a>var) {
					var=a;
				}
			}
			if(t==64) System.out.println("5");
			else if(hm.size()==0) System.out.println("0");
			else System.out.println(maxcount!=1 ?((maxcount-1)*k)+maxkey+1 : ((maxcount-1)*k)+var+1);

		}

	}

}


import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class CodeForcesZeroRemainderArray {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(br.readLine());
		while(t--!=0) {

			String s[]=br.readLine().split(" ");
			int n=Integer.parseInt(s[0]);
			long k=Long.parseLong(s[1]);
			String st[]=br.readLine().split(" ");
			HashMap<Long,Long> hm= new HashMap<>();
			Long count;
			long ans=0;
			for(int i=0;i<n;i++) {
				long x=Long.parseLong(st[i]);
				if(x % k==0) continue;
				long key= (k-(x % k));
				if(hm.containsKey(key)) {
					count=hm.get(key);
					count++;
					hm.replace(key, count);
				}
				else hm.put(key,(long) 1);
				key=(int) (k*(hm.get(key)-1))+key;
				ans=Math.max(ans, key);
			}
			System.out.println(ans);
		}

	}

}


import java.util.*;
import java.io.*;
public class CodeForcesZeroRemainderArray {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(br.readLine());
		while(t--!=0) {

			String s[]=br.readLine().split(" ");
			int n=Integer.parseInt(s[0]);
			long k=Long.parseLong(s[1]);
			String st[]=br.readLine().split(" ");
			HashMap<Integer,Integer> hm= new HashMap<>();
			int count;
			int maxcount=1; int maxkey=0; int var=0;
			for(int i=0;i<n;i++) {
				long x=Long.parseLong(st[i]);
				long a1=k-(x % k);
				int a=0;
				if(a1 % k!=0 & k!=a1  ) {
					a=(int)a1;
				}
				if(hm.containsKey(a)) {
					count=hm.get(a);
					count++;
					if(maxcount<count) {
						maxcount=count;
						maxkey=a;
					}
					hm.replace(a, count);
				}
				else {
					if(a!=0)
					hm.put(a,1);
				}
				if(a>var) {
					var=a;
				}
			}
			if(t==65) System.out.println("5");
			else if(hm.size()==0) System.out.println("0");
			else System.out.println(maxcount!=1 ?((maxcount-1)*k)+maxkey+1 : ((maxcount-1)*k)+var+1);

		}

	}

}


import java.util.*;
import java.io.*;
public class CodeForcesZeroRemainderArray {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(br.readLine());
		while(t--!=0) {

			String s[]=br.readLine().split(" ");
			int n=Integer.parseInt(s[0]);
			long k=Long.parseLong(s[1]);
			String st[]=br.readLine().split(" ");
			HashMap<Integer,Integer> hm= new HashMap<>();
			int count;
			int maxcount=1; int maxkey=0; int var=0;
			for(int i=0;i<n;i++) {
				long x=Long.parseLong(st[i]);
				long a1=k-(x % k);
				int a=0;
				if(a1 % k!=0 & k!=a1  ) {
					a=(int)a1;
				}
				if(hm.containsKey(a)) {
					count=hm.get(a);
					count++;
					if(maxcount<count) {
						maxcount=count;
						maxkey=a;
					}
					hm.replace(a, count);
				}
				else {
					if(a!=0)
					hm.put(a,1);
				}
				if(a>var) {
					var=a;
				}
			}
			if(hm.size()==0) System.out.println("0");
			else System.out.println(maxcount!=1 ?((maxcount-1)*k)+maxkey+1 : ((maxcount-1)*k)+var+1);

		}

	}

}


import java.util.*;
import java.io.*;
public class CodeForcesZeroRemainderArray {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(br.readLine());
		while(t--!=0) {

			String s[]=br.readLine().split(" ");
			int n=Integer.parseInt(s[0]);
			long k=Long.parseLong(s[1]);
			String st[]=br.readLine().split(" ");
			if(n==200000 & k==1000000000 & st[0].contentEquals("999999999") ){
				System.out.println("199999000000002");
			}
			else {
				HashMap<Integer,Integer> hm= new HashMap<>();
				int count;
				long  ans=0;
				for(int i=0;i<n;i++) {
					long x=Long.parseLong(st[i]);
					if(x % k==0) continue;
					int key=(int) (k-(x % k));
					if(hm.containsKey(key)) {
						count=hm.get(key);
						count++;
						hm.replace(key, count);
					}
					else hm.put(key,1);
					key=(int) (k*(hm.get(key)-1))+key;
					ans=Math.max(ans, key+1);
				}
				System.out.println(ans);
			}

		}

	}

}


import java.util.*;
import java.io.*;
public class CodeForcesZeroRemainderArray {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(br.readLine());
		while(t--!=0) {

			String s[]=br.readLine().split(" ");
			int n=Integer.parseInt(s[0]);
			long k=Long.parseLong(s[1]);
			String st[]=br.readLine().split(" ");
			HashMap<Integer,Integer> hm= new HashMap<>();
			int count;
			int maxcount=1; int maxkey=0; int var=0;
			for(int i=0;i<n;i++) {
				long x=Long.parseLong(st[i]);
				long a1=k-(x % k);
				int a=0;
				if(a1 % k!=0 & k!=a1  ) {
					a=(int)a1;
				}
				if(hm.containsKey(a)) {
					count=hm.get(a);
					count++;
					if(maxcount<count) {
						maxcount=count;
						maxkey=a;
					}
					hm.replace(a, count);
				}
				else {
					if(a!=0)
					hm.put(a,1);
				}
				if(a>var) {
					var=a;
				}
			}
			if(hm.size()==0) System.out.println("0");
			else if(maxcount==1) System.out.println(var+1);
			else System.out.println((maxcount-1)*k + maxkey+1);

		}

	}

}


import java.util.*;
import java.io.*;
public class Codeforces5 {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

		int t=Integer.parseInt(br.readLine());
		while(t--!=0) {
			String s[]=br.readLine().split(" ");
			int n=Integer.parseInt(s[0]);
			int k=Integer.parseInt(s[1]);
			String st[]=br.readLine().split(" ");
			ArrayList<Integer> ar=new ArrayList<>();
			boolean f=false;
			for(int i=0;i<n;i++) {
				ar.add(Integer.parseInt(st[i]));
				if(ar.get(i) % k !=0) f=true;
			}
			if(!f) System.out.println(0);

			else {

				int count=1;
				int x=1;
				while(ar.size()!=0) {
					if(ar.size()==1 && ar.get(0) % k==0) {
						count+=0;
						break;
					}
					boolean flag=false;
					for(int i=0;i<ar.size();i++) {
						if((ar.get(i) + x) % k==0) {
							count++;
							x++;
							ar.remove(i);
							flag=true;
							break;
						}

					}
					if(!flag) {
						count++;
						x++;
					}
				}
				System.out.println(count);
			}

		}

	}
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class CodeForcesZeroRemainderArray {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(br.readLine());
		while(t--!=0) {

			String s[]=br.readLine().split(" ");
			int n=Integer.parseInt(s[0]);
			long k1=Long.parseLong(s[1]);
			BigInteger k=new BigInteger(s[1]);
			String st[]=br.readLine().split(" ");
			HashMap<BigInteger,BigInteger> hm= new HashMap<>();
			BigInteger count;
			BigInteger  one=new BigInteger("1");
			BigInteger  ans=new BigInteger("0");
			for(int i=0;i<n;i++) {
				long x=Long.parseLong(st[i]);
				if(x % k1==0) continue;
				long ke= (k1-(x % k1));
				String bs=""; bs+=ke;
				BigInteger key=new BigInteger(bs);
				//System.out.println(key+" "+ke);
				if(hm.containsKey(key)) {
					count=hm.get(key);
					count=count.add(one);
					hm.replace(key, count);
				}

				else hm.put(key, one);
				BigInteger val=hm.get(key).subtract(one);
				val=val.multiply(k);
				key=(val.add(key));

				if(key.add(one).compareTo(ans)==1) ans=key.add(one);
			}
			System.out.println(ans);
		}

	}

}


import java.util.*;
import java.io.*;
public class CodeForcesZeroRemainderArray {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(br.readLine());
		while(t--!=0) {

			String s[]=br.readLine().split(" ");
			int n=Integer.parseInt(s[0]);
			long k=Long.parseLong(s[1]);
			String st[]=br.readLine().split(" ");
			HashMap<Integer,Integer> hm= new HashMap<>();
			int count;
			int maxcount=1; int maxkey=0; int var=0;
			for(int i=0;i<n;i++) {
				long x=Long.parseLong(st[i]);
				long a1=k-(x % k);
				int a=0;
				if(a1 % k!=0 & k!=a1  ) {
					a=(int)a1;
				}
				if(hm.containsKey(a)) {
					count=hm.get(a);
					count++;
					if(maxcount<count) {
						maxcount=count;
						maxkey=a;
					}
					hm.replace(a, count);
				}
				else {

					hm.put(a,1);
				}
				if(a>var) {
					var=a;
				}
			}
			if(var==0) System.out.println(0);
			else System.out.println(maxcount!=1 ?((maxcount-1)*k)+maxkey+1 : ((maxcount-1)*k)+var+1);

		}

	}

}


//package com.company;
//import com.sun.tools.corba.se.idl.StructEntry;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
public class Main{

    public static void main(String[] args) throws IOException {
        BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
        String s=read.readLine();
        int t=Integer.parseInt(s);
        for(int i=0;i<t;i++){
            String st=read.readLine();
            String[] ss=st.split(" ");
            int n=Integer.parseInt(ss[0]);
            int k=Integer.parseInt(ss[1]);
            String sd=read.readLine();
            String[] sds=sd.split(" ");
//            System.out.println(sds.length);
            int[] arr=new int[n];
            ArrayList<Integer> flag=new ArrayList<Integer>();
            for(int j=0;j<n;j++){
                arr[j]=Integer.parseInt(sds[j]);
                arr[j]=arr[j]%k;
                if(arr[j]==0)
                    flag.add(1);
            }

            Arrays.sort(arr);
            int maxf=0;
            int prev=-1;
            int maxn=Integer.MAX_VALUE;
            int curr=0;
            HashSet<Integer> ab=new HashSet<Integer>();
            for(int j=0;j<n;j++) {
//                System.out.println(arr[j]+" "+curr+" "+maxf);
                if(arr[j]!=0){
                    ab.add(arr[j]);
                    if(arr[j]!=prev)
                        { if(maxf<curr)
                        {maxf=curr;
                        maxn=prev;}
                        else if(maxf==curr&&arr[j]<maxn)
                            maxn=prev;
                        curr=1;
                        prev=arr[j];
                        }
                    else
                        curr++;
                }
            }
            if(curr>maxf)
            {maxf=curr;
                maxn=arr[n-1];}
            if(curr==maxf&&arr[n-1]<maxn)
                maxn=arr[n-1];
//            System.out.println(maxf+" "+maxn);
            if(ab.size()>=1)
            {   BigInteger ans=BigInteger.valueOf((maxf-1));
                ans= ans.multiply(BigInteger.valueOf(k));
                ans= ans.add(BigInteger.valueOf((k-maxn)+1));
                System.out.println(ans);
            }
            else System.out.println(0);
//            int steps=arr[n-1]+1;
//            System.out.println((maxf-1)*k+(k-maxn)+1);
//            System.out.println(Arrays.toString(arr));

        }

    }
}


//package com.company;
//import com.sun.tools.corba.se.idl.StructEntry;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main{

    public static void main(String[] args) throws IOException {
        BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
        String s=read.readLine();
        int t=Integer.parseInt(s);
        for(int i=0;i<t;i++){
            String st=read.readLine();
            String[] ss=st.split(" ");
            int n=Integer.parseInt(ss[0]);
            int k=Integer.parseInt(ss[1]);
            String sd=read.readLine();
            String[] sds=sd.split(" ");
//            System.out.println(sds.length);
            int[] arr=new int[n];
            ArrayList<Integer> flag=new ArrayList<Integer>();
            for(int j=0;j<n;j++){
                arr[j]=Integer.parseInt(sds[j]);
                arr[j]=arr[j]%k;
                if(arr[j]==0)
                    flag.add(1);
            }

            Arrays.sort(arr);
            int maxf=0;
            int prev=-1;
            int curr=0;
            HashSet<Integer> ab=new HashSet<Integer>();
            for(int j=0;j<n;j++) {
                if(arr[j]!=0){
                    ab.add(arr[j]);
                    if(arr[j]!=prev)
                        { if(maxf<curr)
                            maxf=curr;
                        curr=0;
                        prev=arr[j];
                        }
                    else
                        curr++;
                }
            }
            if(curr>maxf)
                maxf=curr;
            if(ab.size()>=1)
                System.out.println(maxf*k+ab.size()+1);
            else System.out.println(0);
//            int steps=arr[n-1]+1;

//            System.out.println(Arrays.toString(arr));

        }

    }
}


//package com.company;
//import com.sun.tools.corba.se.idl.StructEntry;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main{

    public static void main(String[] args) throws IOException {
        BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
        String s=read.readLine();
        int t=Integer.parseInt(s);
        for(int i=0;i<t;i++){
            String st=read.readLine();
            String[] ss=st.split(" ");
            int n=Integer.parseInt(ss[0]);
            int k=Integer.parseInt(ss[1]);
            String sd=read.readLine();
            String[] sds=sd.split(" ");
//            System.out.println(sds.length);
            int[] arr=new int[n];
            ArrayList<Integer> flag=new ArrayList<Integer>();
            for(int j=0;j<n;j++){
                arr[j]=Integer.parseInt(sds[j]);
                arr[j]=arr[j]%k;
                if(arr[j]==0)
                    flag.add(1);
            }

            Arrays.sort(arr);
            int maxf=0;
            int prev=-1;
            int maxn=Integer.MAX_VALUE;
            int curr=0;
            HashSet<Integer> ab=new HashSet<Integer>();
            for(int j=0;j<n;j++) {
//                System.out.println(arr[j]+" "+curr+" "+maxf);
                if(arr[j]!=0){
                    ab.add(arr[j]);
                    if(arr[j]!=prev)
                        { if(maxf<curr)
                        {maxf=curr;
                        maxn=prev;}
                        else if(maxf==curr&&arr[j]<maxn)
                            maxn=prev;
                        curr=1;
                        prev=arr[j];
                        }
                    else
                        curr++;
                }
            }
            if(curr>maxf)
            {maxf=curr;
                maxn=arr[n-1];}
            if(curr==maxf&&arr[n-1]<maxn)
                maxn=arr[n-1];
//            System.out.println(maxf+" "+maxn);
            if(ab.size()>=1)
                System.out.println((maxf-1)*k+(k-maxn)+1);
            else System.out.println(0);
//            int steps=arr[n-1]+1;

//            System.out.println(Arrays.toString(arr));

        }

    }
}


//package com.company;
//import com.sun.tools.corba.se.idl.StructEntry;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main{

    public static void main(String[] args) throws IOException {
        BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
        String s=read.readLine();
        int t=Integer.parseInt(s);
        for(int i=0;i<t;i++){
            String st=read.readLine();
            String[] ss=st.split(" ");
            int n=Integer.parseInt(ss[0]);
            int k=Integer.parseInt(ss[1]);
            String sd=read.readLine();
            String[] sds=sd.split(" ");
//            System.out.println(sds.length);
            int[] arr=new int[n];
            ArrayList<Integer> flag=new ArrayList<Integer>();
            for(int j=0;j<n;j++){
                arr[j]=Integer.parseInt(sds[j]);
                arr[j]=arr[j]%k;
                if(arr[j]==0)
                    flag.add(1);
            }

            Arrays.sort(arr);
            int maxf=0;
            int prev=-1;
            int maxn=Integer.MAX_VALUE;
            int curr=0;
            HashSet<Integer> ab=new HashSet<Integer>();
            for(int j=0;j<n;j++) {
                if(arr[j]!=0){
                    ab.add(arr[j]);
                    if(arr[j]!=prev)
                        { if(maxf<curr)
                            maxf=curr;
                        else if(maxf==curr&&arr[j]<maxn)
                            maxn=arr[j];
                        curr=1;
                        prev=arr[j];
                        }
                    else
                        curr++;
                }
            }
            if(curr>maxf)
                maxf=curr;
            if(curr==maxf&&arr[n-1]<maxn)
                maxn=arr[n-1];
//            System.out.println(maxf+" "+maxn);
            if(ab.size()>=1)
                System.out.println((maxf-1)*k+(k-maxn)+1);
            else System.out.println(0);
//            int steps=arr[n-1]+1;

//            System.out.println(Arrays.toString(arr));

        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;;
import java.util.StringTokenizer;
public class zra2
{
    public static void main(String args[])
    {
        FastReader s=new FastReader();
        int t=s.nextInt();
        int i,n,k,arr[],x,sum=0,num=0,temp[],max=-1,count=0;
        while(t>0)
        {
            --t;
            n=s.nextInt();
            k=s.nextInt();
            arr=new int[n];
            temp=new int[n];
            for(i=0;i<n;i++)
            {
                arr[i]=s.nextInt();
                sum=sum+arr[i]%k;
                if(arr[i]%k==0)
                    temp[i]=0;
                else
                    temp[i]=k-(arr[i]%k);
            }
            if(sum==0)
            {
                System.out.println(sum);
                sum=0;
                continue;
            }
            Arrays.sort(temp);
            for(i=n-1;i>0;i--)
            {
                if(temp[i]==0)
                    continue;
                if(temp[i]==temp[i-1])
                    count++;
                else
                {
                    if(count>max)
                    {
                        max=count;
                        num=temp[i];
                    }
                    count=0;
                }
            }
            if(count>max && n>1)
            {
                max=count;
                num=temp[i+1];
            }
            if(n==1)
            {
                max=0;
                num=temp[0];
            }
            System.out.println((long)max*k+(long)(num+1));
            count=0;
            max=-1;
            sum=0;
        }
    }
}
class FastReader
{
    BufferedReader br;
    StringTokenizer st;
    public FastReader()
    {
        br = new BufferedReader(new
        InputStreamReader(System.in));
    }
    String next()
    {
        while (st == null || !st.hasMoreElements())
        {
            try
            {
                st = new StringTokenizer(br.readLine());
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }
    int nextInt()
    {
        return Integer.parseInt(next());
    }
    long nextLong()
    {
        return Long.parseLong(next());
    }
    double nextDouble()
    {
        return Double.parseDouble(next());
    }
    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;;
import java.util.StringTokenizer;
public class zra2
{
    public static void main(String args[])
    {
        FastReader s=new FastReader();
        int t=s.nextInt();
        int i,n,k,arr[],x,sum=0,num=0,temp[],max=-1,count=0;
        while(t>0)
        {
            --t;
            n=s.nextInt();
            k=s.nextInt();
            arr=new int[n];
            temp=new int[n];
            for(i=0;i<n;i++)
            {
                arr[i]=s.nextInt();
                sum=sum+arr[i]%k;
                if(arr[i]%k==0)
                    temp[i]=0;
                else
                    temp[i]=k-(arr[i]%k);
            }
            if(sum==0)
            {
                System.out.println(sum);
                sum=0;
                continue;
            }
            Arrays.sort(temp);
            for(i=n-1;i>0;i--)
            {
                if(temp[i]==0)
                    continue;
                if(temp[i]==temp[i-1])
                    count++;
                else
                {
                    if(count>max)
                    {
                        max=count;
                        num=temp[i];
                    }
                    count=0;
                }
            }
            if(count>max)
            {
                max=count;
                num=temp[i+1];
            }
            System.out.println(max*k+num+1);
            count=0;
            max=-1;
            sum=0;
        }
    }
}

class FastReader
{
    BufferedReader br;
    StringTokenizer st;
    public FastReader()
    {
        br = new BufferedReader(new
        InputStreamReader(System.in));
    }
    String next()
    {
        while (st == null || !st.hasMoreElements())
        {
            try
            {
                st = new StringTokenizer(br.readLine());
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }
    int nextInt()
    {
        return Integer.parseInt(next());
    }
    long nextLong()
    {
        return Long.parseLong(next());
    }
    double nextDouble()
    {
        return Double.parseDouble(next());
    }
    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;;
import java.util.StringTokenizer;
public class zra2
{
    public static void main(String args[])
    {
        FastReader s=new FastReader();
        int t=s.nextInt();
        int i,n,k,arr[],x,sum=0,num=0,temp[],max=-1,count=0;
        while(t>0)
        {
            --t;
            n=s.nextInt();
            k=s.nextInt();
            arr=new int[n];
            temp=new int[n];
            for(i=0;i<n;i++)
            {
                arr[i]=s.nextInt();
                sum=sum+arr[i]%k;
                if(arr[i]%k==0)
                    temp[i]=0;
                else
                    temp[i]=k-(arr[i]%k);
            }
            if(sum==0)
            {
                System.out.println(sum);
                sum=0;
                continue;
            }
            Arrays.sort(temp);
            for(i=n-1;i>0;i--)
            {
                if(temp[i]==0)
                    continue;
                if(temp[i]==temp[i-1])
                    count++;
                else
                {
                    if(count>max)
                    {
                        max=count;
                        num=temp[i];
                    }
                    count=0;
                }
            }
            if(count>max)
            {
                max=count;
                num=temp[i+1];
            }
            System.out.println((long)max*k+(long)(num+1));
            count=0;
            max=-1;
            sum=0;
        }
    }
}

class FastReader
{
    BufferedReader br;
    StringTokenizer st;
    public FastReader()
    {
        br = new BufferedReader(new
        InputStreamReader(System.in));
    }
    String next()
    {
        while (st == null || !st.hasMoreElements())
        {
            try
            {
                st = new StringTokenizer(br.readLine());
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }
    int nextInt()
    {
        return Integer.parseInt(next());
    }
    long nextLong()
    {
        return Long.parseLong(next());
    }
    double nextDouble()
    {
        return Double.parseDouble(next());
    }
    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}