/*   盗图小能手
⣿⣿⣿⣿⣿⣿⡷⣯⢿⣿⣷⣻⢯⣿⡽⣻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠸⣿⣿⣆⠹⣿⣿⢾⣟⣯⣿⣿⣿⣿⣿⣿⣽⣻⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣻⣽⡿⣿⣎⠙⣿⣞⣷⡌⢻⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⡄⠹⣿⣿⡆⠻⣿⣟⣯⡿⣽⡿⣿⣿⣿⣿⣽⡷⣯⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣷⣿⣿⣿⡀⠹⣟⣾⣟⣆⠹⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢠⡘⣿⣿⡄⠉⢿⣿⣽⡷⣿⣻⣿⣿⣿⣿⡝⣷⣯⢿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣯⢿⣾⢿⣿⡄⢄⠘⢿⣞⡿⣧⡈⢷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣧⠘⣿⣷⠈⣦⠙⢿⣽⣷⣻⣽⣿⣿⣿⣿⣌⢿⣯⢿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣯⣿⢿⣿⡆⢸⡷⡈⢻⡽⣷⡷⡄⠻⣽⣿⣿⡿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣏⢰⣯⢷⠈⣿⡆⢹⢷⡌⠻⡾⢋⣱⣯⣿⣿⣿⣿⡆⢻⡿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⡎⣿⢾⡿⣿⡆⢸⣽⢻⣄⠹⣷⣟⣿⣄⠹⣟⣿⣿⣟⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⢸⣯⣟⣧⠘⣷⠈⡯⠛⢀⡐⢾⣟⣷⣻⣿⣿⣿⡿⡌⢿⣻⣿⣿
⣿⣿⣿⣿⣿⣿⣧⢸⡿⣟⣿⡇⢸⣯⣟⣮⢧⡈⢿⣞⡿⣦⠘⠏⣹⣿⣽⢿⣿⣿⣿⣿⣯⣿⣿⣿⡇⢸⣿⣿⣾⡆⠹⢀⣠⣾⣟⣷⡈⢿⣞⣯⢿⣿⣿⣿⢷⠘⣯⣿⣿
⣿⣿⣿⣿⣿⣿⣿⡈⣿⢿⣽⡇⠘⠛⠛⠛⠓⠓⠈⠛⠛⠟⠇⢀⢿⣻⣿⣯⢿⣿⣿⣿⣷⢿⣿⣿⠁⣾⣿⣿⣿⣧⡄⠇⣹⣿⣾⣯⣿⡄⠻⣽⣯⢿⣻⣿⣿⡇⢹⣾⣿
⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⡽⡇⢸⣿⣿⣿⣿⣿⣞⣆⠰⣶⣶⡄⢀⢻⡿⣯⣿⡽⣿⣿⣿⢯⣟⡿⢀⣿⣿⣿⣿⣿⣧⠐⣸⣿⣿⣷⣿⣿⣆⠹⣯⣿⣻⣿⣿⣿⢀⣿⢿
⣿⣿⣿⣿⣿⣿⣿⣿⠘⣯⡿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣧⡈⢿⣳⠘⡄⠻⣿⢾⣽⣟⡿⣿⢯⣿⡇⢸⣿⣿⣿⣿⣿⣿⡀⢾⣿⣿⣿⣿⣿⣿⣆⠹⣾⣷⣻⣿⡿⡇⢸⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⠇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠻⡇⢹⣆⠹⣟⣾⣽⣻⣟⣿⣽⠁⣾⣿⣿⣿⣿⣿⣿⣇⣿⣿⠿⠛⠛⠉⠙⠋⢀⠁⢘⣯⣿⣿⣧⠘⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⡈⣿⡃⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡙⠌⣿⣆⠘⣿⣞⡿⣞⡿⡞⢠⣿⣿⣿⣿⣿⡿⠛⠉⠁⢀⣀⣠⣤⣤⣶⣶⣶⡆⢻⣽⣞⡿⣷⠈⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠘⠁⠉⠉⠉⠉⠉⠉⠉⠉⠉⠙⠛⠛⢿⣄⢻⣿⣧⠘⢯⣟⡿⣽⠁⣾⣿⣿⣿⣿⣿⡃⢀⢀⠘⠛⠿⢿⣻⣟⣯⣽⣻⣵⡀⢿⣯⣟⣿⢀⣿
⣿⣿⣿⣟⣿⣿⣿⣿⣶⣶⡆⢀⣿⣾⣿⣾⣷⣿⣶⠿⠚⠉⢀⢀⣤⣿⣷⣿⣿⣷⡈⢿⣻⢃⣼⣿⣿⣿⣿⣻⣿⣿⣿⡶⣦⣤⣄⣀⡀⠉⠛⠛⠷⣯⣳⠈⣾⡽⣾⢀⣿
⣿⢿⣿⣿⣻⣿⣿⣿⣿⣿⡿⠐⣿⣿⣿⣿⠿⠋⠁⢀⢀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣌⣥⣾⡿⣿⣿⣷⣿⣿⢿⣷⣿⣿⣟⣾⣽⣳⢯⣟⣶⣦⣤⡾⣟⣦⠘⣿⢾⡁⢺
⣿⣻⣿⣿⡷⣿⣿⣿⣿⣿⡗⣦⠸⡿⠋⠁⢀⢀⣠⣴⢿⣿⣽⣻⢽⣾⣟⣷⣿⣟⣿⣿⣿⣳⠿⣵⣧⣼⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣽⣳⣯⣿⣿⣿⣽⢀⢷⣻⠄⠘
⣿⢷⣻⣿⣿⣷⣻⣿⣿⣿⡷⠛⣁⢀⣀⣤⣶⣿⣛⡿⣿⣮⣽⡻⣿⣮⣽⣻⢯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⢀⢸⣿⢀⡆
⠸⣟⣯⣿⣿⣷⢿⣽⣿⣿⣷⣿⣷⣆⠹⣿⣶⣯⠿⣿⣶⣟⣻⢿⣷⣽⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢀⣯⣟⢀⡇
⣇⠹⣟⣾⣻⣿⣿⢾⡽⣿⣿⣿⣿⣿⣆⢹⣶⣿⣻⣷⣯⣟⣿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢀⡿⡇⢸⡇
⣿⣆⠹⣷⡻⣽⣿⣯⢿⣽⣻⣿⣿⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⢸⣿⠇⣼⡇
⡙⠾⣆⠹⣿⣦⠛⣿⢯⣷⢿⡽⣿⣿⣿⣿⣆⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠎⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⢀⣿⣾⣣⡿⡇
⣿⣷⡌⢦⠙⣿⣿⣌⠻⣽⢯⣿⣽⣻⣿⣿⣿⣧⠩⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⢰⢣⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⢀⢀⢿⣞⣷⢿⡇
⣿⣽⣆⠹⣧⠘⣿⣿⡷⣌⠙⢷⣯⡷⣟⣿⣿⣿⣷⡀⡹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣈⠃⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⢀⣴⡧⢀⠸⣿⡽⣿⢀
⢻⣽⣿⡄⢻⣷⡈⢿⣿⣿⢧⢀⠙⢿⣻⡾⣽⣻⣿⣿⣄⠌⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢁⣰⣾⣟⡿⢀⡄⢿⣟⣿⢀
⡄⢿⣿⣷⢀⠹⣟⣆⠻⣿⣿⣆⢀⣀⠉⠻⣿⡽⣯⣿⣿⣷⣈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⢀⣠⠘⣯⣷⣿⡟⢀⢆⠸⣿⡟⢸
⣷⡈⢿⣿⣇⢱⡘⢿⣷⣬⣙⠿⣧⠘⣆⢀⠈⠻⣷⣟⣾⢿⣿⣆⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⣠⡞⢡⣿⢀⣿⣿⣿⠇⡄⢸⡄⢻⡇⣼
⣿⣷⡈⢿⣿⡆⢣⡀⠙⢾⣟⣿⣿⣷⡈⠂⠘⣦⡈⠿⣯⣿⢾⣿⣆⠙⠻⠿⠿⠿⠿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢋⣠⣾⡟⢠⣿⣿⢀⣿⣿⡟⢠⣿⢈⣧⠘⢠⣿
⣿⣿⣿⣄⠻⣿⡄⢳⡄⢆⡙⠾⣽⣿⣿⣆⡀⢹⡷⣄⠙⢿⣿⡾⣿⣆⢀⡀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣀⣠⣴⡿⣯⠏⣠⣿⣿⡏⢸⣿⡿⢁⣿⣿⢀⣿⠆⢸⣿
⣿⣿⣿⣿⣦⡙⣿⣆⢻⡌⢿⣶⢤⣉⣙⣿⣷⡀⠙⠽⠷⠄⠹⣿⣟⣿⣆⢙⣋⣤⣤⣤⣄⣀⢀⢀⢀⢀⣾⣿⣟⡷⣯⡿⢃⣼⣿⣿⣿⠇⣼⡟⣡⣿⣿⣿⢀⡿⢠⠈⣿
⣿⣿⣿⣿⣿⣷⣮⣿⣿⣿⡌⠁⢤⣤⣤⣤⣬⣭⣴⣶⣶⣶⣆⠈⢻⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣷⣶⣤⣌⣉⡘⠛⠻⠶⣿⣿⣿⣿⡟⣰⣫⣴⣿⣿⣿⣿⠄⣷⣿⣿⣿
*/

import javax.sound.midi.Soundbank;
import java.io.*;
import java.util.*;

public class D {

    /**
     * TODO 提交的时候一定要设置为 true
     */
    boolean submitFlag = true;

    private void solve(int k, Map<Integer, Integer> map) {
        int mod = 0;
        int index = 0;

//        System.out.println(Arrays.toString(num));
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            Integer integer = entry.getKey();
            Integer integer2 = entry.getValue();
            if (integer2 > mod || integer < index) {
                mod = integer2;
                index = integer;
            }
        }

        if (mod > 0) {
            // 补值
            int gg = k - index + 1;
            System.out.println((mod - 1) * k + gg);
        } else {
            System.out.println(0);
        }

    }

    private void run() throws IOException {
        //TODO 从这里开始读入题目输入
        int numberOfTestcases = nextInt();

        for (int t = 0; t < numberOfTestcases; t++) {
            int n = nextInt();
            int k = nextInt();
            // 余数累计
            Map<Integer, Integer> map = new HashMap<>();
            int[] num = new int[k];
            for (int i = 0; i < n; i++) {
                int data = nextInt();
                int key = data % k;
                Integer orDefault = map.getOrDefault(key, 0);
                map.put(key, orDefault + 1);
            }
            solve(k, map);
        }

    }

//    main以及输入输出========================================================================

    public static void main(String[] args) throws IOException {
        D solution = new D();
        solution.setReader();
        solution.run();
        solution.reader.close();
    }

    /**
     * 注意不同题目这里路径要设一下
     *
     * @throws IOException
     */
    private void setReader() throws IOException {
        if (submitFlag) {
            reader = new BufferedReader(new InputStreamReader(System.in));
        } else {
            String path = this.getClass().getResource("").getPath();
            File file = new File(path);
            while (!file.getName().equals("target")) {
                file = file.getParentFile();
            }
            String moduleName = file.getParentFile().getName();
            String projectPath = System.getProperty("user.dir");
            String modulePath = projectPath + "/" + moduleName + "/src/main/java/";
            String className = this.getClass().getName().replace(".", "\\");
            reader = new BufferedReader(new FileReader(modulePath + className + "input.txt"));
        }
    }

    BufferedReader reader;
    StringTokenizer tokenizer;

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String next() throws IOException {
        return nextToken();
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


/*   盗图小能手
⣿⣿⣿⣿⣿⣿⡷⣯⢿⣿⣷⣻⢯⣿⡽⣻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠸⣿⣿⣆⠹⣿⣿⢾⣟⣯⣿⣿⣿⣿⣿⣿⣽⣻⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣻⣽⡿⣿⣎⠙⣿⣞⣷⡌⢻⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⡄⠹⣿⣿⡆⠻⣿⣟⣯⡿⣽⡿⣿⣿⣿⣿⣽⡷⣯⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣷⣿⣿⣿⡀⠹⣟⣾⣟⣆⠹⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢠⡘⣿⣿⡄⠉⢿⣿⣽⡷⣿⣻⣿⣿⣿⣿⡝⣷⣯⢿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣯⢿⣾⢿⣿⡄⢄⠘⢿⣞⡿⣧⡈⢷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣧⠘⣿⣷⠈⣦⠙⢿⣽⣷⣻⣽⣿⣿⣿⣿⣌⢿⣯⢿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣯⣿⢿⣿⡆⢸⡷⡈⢻⡽⣷⡷⡄⠻⣽⣿⣿⡿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣏⢰⣯⢷⠈⣿⡆⢹⢷⡌⠻⡾⢋⣱⣯⣿⣿⣿⣿⡆⢻⡿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⡎⣿⢾⡿⣿⡆⢸⣽⢻⣄⠹⣷⣟⣿⣄⠹⣟⣿⣿⣟⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⢸⣯⣟⣧⠘⣷⠈⡯⠛⢀⡐⢾⣟⣷⣻⣿⣿⣿⡿⡌⢿⣻⣿⣿
⣿⣿⣿⣿⣿⣿⣧⢸⡿⣟⣿⡇⢸⣯⣟⣮⢧⡈⢿⣞⡿⣦⠘⠏⣹⣿⣽⢿⣿⣿⣿⣿⣯⣿⣿⣿⡇⢸⣿⣿⣾⡆⠹⢀⣠⣾⣟⣷⡈⢿⣞⣯⢿⣿⣿⣿⢷⠘⣯⣿⣿
⣿⣿⣿⣿⣿⣿⣿⡈⣿⢿⣽⡇⠘⠛⠛⠛⠓⠓⠈⠛⠛⠟⠇⢀⢿⣻⣿⣯⢿⣿⣿⣿⣷⢿⣿⣿⠁⣾⣿⣿⣿⣧⡄⠇⣹⣿⣾⣯⣿⡄⠻⣽⣯⢿⣻⣿⣿⡇⢹⣾⣿
⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⡽⡇⢸⣿⣿⣿⣿⣿⣞⣆⠰⣶⣶⡄⢀⢻⡿⣯⣿⡽⣿⣿⣿⢯⣟⡿⢀⣿⣿⣿⣿⣿⣧⠐⣸⣿⣿⣷⣿⣿⣆⠹⣯⣿⣻⣿⣿⣿⢀⣿⢿
⣿⣿⣿⣿⣿⣿⣿⣿⠘⣯⡿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣧⡈⢿⣳⠘⡄⠻⣿⢾⣽⣟⡿⣿⢯⣿⡇⢸⣿⣿⣿⣿⣿⣿⡀⢾⣿⣿⣿⣿⣿⣿⣆⠹⣾⣷⣻⣿⡿⡇⢸⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⠇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠻⡇⢹⣆⠹⣟⣾⣽⣻⣟⣿⣽⠁⣾⣿⣿⣿⣿⣿⣿⣇⣿⣿⠿⠛⠛⠉⠙⠋⢀⠁⢘⣯⣿⣿⣧⠘⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⡈⣿⡃⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡙⠌⣿⣆⠘⣿⣞⡿⣞⡿⡞⢠⣿⣿⣿⣿⣿⡿⠛⠉⠁⢀⣀⣠⣤⣤⣶⣶⣶⡆⢻⣽⣞⡿⣷⠈⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠘⠁⠉⠉⠉⠉⠉⠉⠉⠉⠉⠙⠛⠛⢿⣄⢻⣿⣧⠘⢯⣟⡿⣽⠁⣾⣿⣿⣿⣿⣿⡃⢀⢀⠘⠛⠿⢿⣻⣟⣯⣽⣻⣵⡀⢿⣯⣟⣿⢀⣿
⣿⣿⣿⣟⣿⣿⣿⣿⣶⣶⡆⢀⣿⣾⣿⣾⣷⣿⣶⠿⠚⠉⢀⢀⣤⣿⣷⣿⣿⣷⡈⢿⣻⢃⣼⣿⣿⣿⣿⣻⣿⣿⣿⡶⣦⣤⣄⣀⡀⠉⠛⠛⠷⣯⣳⠈⣾⡽⣾⢀⣿
⣿⢿⣿⣿⣻⣿⣿⣿⣿⣿⡿⠐⣿⣿⣿⣿⠿⠋⠁⢀⢀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣌⣥⣾⡿⣿⣿⣷⣿⣿⢿⣷⣿⣿⣟⣾⣽⣳⢯⣟⣶⣦⣤⡾⣟⣦⠘⣿⢾⡁⢺
⣿⣻⣿⣿⡷⣿⣿⣿⣿⣿⡗⣦⠸⡿⠋⠁⢀⢀⣠⣴⢿⣿⣽⣻⢽⣾⣟⣷⣿⣟⣿⣿⣿⣳⠿⣵⣧⣼⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣽⣳⣯⣿⣿⣿⣽⢀⢷⣻⠄⠘
⣿⢷⣻⣿⣿⣷⣻⣿⣿⣿⡷⠛⣁⢀⣀⣤⣶⣿⣛⡿⣿⣮⣽⡻⣿⣮⣽⣻⢯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⢀⢸⣿⢀⡆
⠸⣟⣯⣿⣿⣷⢿⣽⣿⣿⣷⣿⣷⣆⠹⣿⣶⣯⠿⣿⣶⣟⣻⢿⣷⣽⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢀⣯⣟⢀⡇
⣇⠹⣟⣾⣻⣿⣿⢾⡽⣿⣿⣿⣿⣿⣆⢹⣶⣿⣻⣷⣯⣟⣿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢀⡿⡇⢸⡇
⣿⣆⠹⣷⡻⣽⣿⣯⢿⣽⣻⣿⣿⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⢸⣿⠇⣼⡇
⡙⠾⣆⠹⣿⣦⠛⣿⢯⣷⢿⡽⣿⣿⣿⣿⣆⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠎⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⢀⣿⣾⣣⡿⡇
⣿⣷⡌⢦⠙⣿⣿⣌⠻⣽⢯⣿⣽⣻⣿⣿⣿⣧⠩⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⢰⢣⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⢀⢀⢿⣞⣷⢿⡇
⣿⣽⣆⠹⣧⠘⣿⣿⡷⣌⠙⢷⣯⡷⣟⣿⣿⣿⣷⡀⡹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣈⠃⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⢀⣴⡧⢀⠸⣿⡽⣿⢀
⢻⣽⣿⡄⢻⣷⡈⢿⣿⣿⢧⢀⠙⢿⣻⡾⣽⣻⣿⣿⣄⠌⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢁⣰⣾⣟⡿⢀⡄⢿⣟⣿⢀
⡄⢿⣿⣷⢀⠹⣟⣆⠻⣿⣿⣆⢀⣀⠉⠻⣿⡽⣯⣿⣿⣷⣈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⢀⣠⠘⣯⣷⣿⡟⢀⢆⠸⣿⡟⢸
⣷⡈⢿⣿⣇⢱⡘⢿⣷⣬⣙⠿⣧⠘⣆⢀⠈⠻⣷⣟⣾⢿⣿⣆⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⣠⡞⢡⣿⢀⣿⣿⣿⠇⡄⢸⡄⢻⡇⣼
⣿⣷⡈⢿⣿⡆⢣⡀⠙⢾⣟⣿⣿⣷⡈⠂⠘⣦⡈⠿⣯⣿⢾⣿⣆⠙⠻⠿⠿⠿⠿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢋⣠⣾⡟⢠⣿⣿⢀⣿⣿⡟⢠⣿⢈⣧⠘⢠⣿
⣿⣿⣿⣄⠻⣿⡄⢳⡄⢆⡙⠾⣽⣿⣿⣆⡀⢹⡷⣄⠙⢿⣿⡾⣿⣆⢀⡀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣀⣠⣴⡿⣯⠏⣠⣿⣿⡏⢸⣿⡿⢁⣿⣿⢀⣿⠆⢸⣿
⣿⣿⣿⣿⣦⡙⣿⣆⢻⡌⢿⣶⢤⣉⣙⣿⣷⡀⠙⠽⠷⠄⠹⣿⣟⣿⣆⢙⣋⣤⣤⣤⣄⣀⢀⢀⢀⢀⣾⣿⣟⡷⣯⡿⢃⣼⣿⣿⣿⠇⣼⡟⣡⣿⣿⣿⢀⡿⢠⠈⣿
⣿⣿⣿⣿⣿⣷⣮⣿⣿⣿⡌⠁⢤⣤⣤⣤⣬⣭⣴⣶⣶⣶⣆⠈⢻⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣷⣶⣤⣌⣉⡘⠛⠻⠶⣿⣿⣿⣿⡟⣰⣫⣴⣿⣿⣿⣿⠄⣷⣿⣿⣿
*/

import javax.sound.midi.Soundbank;
import java.io.*;
import java.util.*;

public class D {

    /**
     * TODO 提交的时候一定要设置为 true
     */
    boolean submitFlag = false;

    private void solve(int n, int k, int[] a) {
        int mod = 0;
        int index = 0;
        // 余数累计
        int[] num = new int[k];
        for (int i = 0; i < a.length; i++) {
            num[a[i] % k]++;
        }
//        System.out.println(Arrays.toString(num));

        for (int i = 1; i < k; i++) {
            if (num[i] > mod) {
                mod = num[i];
                index = i;
            }
        }

        if (mod > 0) {
            // 补值
            int gg = k - index+1;
            System.out.println((mod - 1) * k + gg);
        } else {
            System.out.println(0);
        }

    }

    private void run() throws IOException {
        //TODO 从这里开始读入题目输入
        int numberOfTestcases = nextInt();

        for (int t = 0; t < numberOfTestcases; t++) {
            int n = nextInt();
            int k = nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            solve(n, k, a);
        }

    }

//    main以及输入输出========================================================================

    public static void main(String[] args) throws IOException {
        D solution = new D();
        solution.setReader();
        solution.run();
        solution.reader.close();
    }

    /**
     * 注意不同题目这里路径要设一下
     *
     * @throws IOException
     */
    private void setReader() throws IOException {
        if (submitFlag) {
            reader = new BufferedReader(new InputStreamReader(System.in));
        } else {
            String path = this.getClass().getResource("").getPath();
            File file = new File(path);
            while (!file.getName().equals("target")) {
                file = file.getParentFile();
            }
            String moduleName = file.getParentFile().getName();
            String projectPath = System.getProperty("user.dir");
            String modulePath = projectPath + "/" + moduleName + "/src/main/java/";
            String className = this.getClass().getName().replace(".", "\\");
            reader = new BufferedReader(new FileReader(modulePath + className + "input.txt"));
        }
    }

    BufferedReader reader;
    StringTokenizer tokenizer;

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String next() throws IOException {
        return nextToken();
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int test_case = scanner.nextInt();

        for(int i = 0; i < test_case; ++i)
        {
            int n = scanner.nextInt();
            int k = scanner.nextInt();
            HashMap<Integer,Integer> hm = new HashMap<>();
            int res = 0;
            int max_ciclos = 0;
            int menor_ciclos = Integer.MAX_VALUE;
            for(int j = 0; j < n; ++j)
            {
                int temp = scanner.nextInt() % k;
                int value = 1;
                if(temp != 0){
                    if(hm.containsKey(temp))
                    {
                    value = hm.get(temp) + 1;
                    hm.remove(temp);
                    }
                   hm.put(temp, value);
                        if(value > max_ciclos)
                        {
                         max_ciclos = value;
                         menor_ciclos = temp;
                        }
                        else if(value == max_ciclos) menor_ciclos = Math.min(menor_ciclos, temp);
                }
            }

            if(max_ciclos > 0)
            {
                res = (max_ciclos-1)*k + (k-menor_ciclos);
            }
            //hallar el minimo con el nuemro de ciclos y fin.

            if(res > 0)++res;
            System.out.println(res);
        }
    }
}


import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int test_case = scanner.nextInt();

        for(int i = 0; i < test_case; ++i)
        {
            int n = scanner.nextInt();
            int k = scanner.nextInt();
            HashMap<Integer,Integer> hm = new HashMap<>();
            int res = 0;
            int max_ciclos = 0;
            int menor_ciclos = Integer.MAX_VALUE;
            for(int j = 0; j < n; ++j)
            {
                int temp = scanner.nextInt() % k;
                int value = 1;
                if(temp != 0){
                    if(hm.containsKey(temp))
                    {
                    value = hm.get(temp) + 1;
                    hm.remove(temp);
                    }
                   hm.put(temp, value);
                        if(value >= max_ciclos)
                     {
                         max_ciclos = value;
                         menor_ciclos = Math.min(menor_ciclos, temp);
                     }
                }

            }

            if(max_ciclos > 0)
            {
                res = (max_ciclos-1)*k + (k-menor_ciclos);
            }
            //hallar el minimo con el nuemro de ciclos y fin.

            if(res > 0)++res;
            System.out.println(res);
        }
    }
}


import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int test_case = scanner.nextInt();

        for(int i = 0; i < test_case; ++i)
        {
            int n = scanner.nextInt();
            int k = scanner.nextInt();
            HashMap<Integer,Integer> hm = new HashMap<>();
            int res = 0;
            for(int j = 0; j < n; ++j)
            {
                int temp = scanner.nextInt() % k;
                if(temp != 0){
                if(hm.containsKey(temp))
                {
                    int t = hm.get(temp);
                    hm.replace(temp, t+1);
                }
                else hm.put(temp, 1);
                }
            }
            //contar  ciclos
            int max_ciclos = 0;
            int menor_ciclos = -1;
             for(int j = 1; j < k; ++j)
             {
                 if(hm.containsKey(j))
                 {
                     if(hm.get(j) > max_ciclos)
                     {
                         max_ciclos = hm.get(j);
                         menor_ciclos = j;
                     }
                 }
             }
            if(max_ciclos > 0)
            {
                res = (max_ciclos-1)*k + (k-menor_ciclos);
            }
            //hallar el minimo con el nuemro de ciclos y fin.

            if(res > 0)++res;
            System.out.println(res);
        }
    }
}


import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int test_case = scanner.nextInt();

            for(int i = 0; i < test_case; ++i)
            {
                int n = scanner.nextInt();
                long k = scanner.nextLong();

                long res = 0L;
                long max_value = 0L;
                long max_k = 0;

                HashMap<Long,Long> hm = new HashMap<>();
                for(int j = 0; j < n; ++j)
                {
                    long temp = scanner.nextLong();
                    temp %= k;

                    long value = 1L;
                    if(temp != 0){
                                    if(hm.containsKey(temp))
                                    {
                                        value = hm.get(temp) + 1;
                                        hm.remove(temp);
                                    }
                                   hm.put(temp, value);

                            if(value > max_value)
                            {
                             max_value = value;
                             max_k = k-temp;
                            }
                            else if(value == max_value) max_k = Math.max(max_k, k-temp);
                    }
                }

                if(max_value > 1)
                {
                    res = ((max_value-1)*k) + (max_k);

                }
                else if(max_value == 1)
                {
                    res = max_k;

                }
                //hallar el minimo con el nuemro de ciclos y fin.

                if(res > 0)++res;
                System.out.println(res);
            }
    }
}
// 2 1 1 2 3 1 5 4 2 3


import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int test_case = scanner.nextInt();

        for(int i = 0; i < test_case; ++i)
        {
            int n = scanner.nextInt();
            int k = scanner.nextInt();
            int[] array = new int[k];
            HashMap<Integer,Integer> hm = new HashMap<>();
            int res = 0;
            for(int j = 0; j < n; ++j)
            {
                int temp = scanner.nextInt() % k;
                array[temp] += 1;
            }
            //contar  ciclos
            int max_ciclos = 0;
            int menor_ciclos = -1;
             for(int j = 1; j < k; ++j)
             {

                     if(array[j] > max_ciclos)
                     {
                         max_ciclos = array[j];
                         menor_ciclos = j;
                     }

             }
            if(max_ciclos > 0)
            {
                res = (max_ciclos-1)*k + (k-menor_ciclos);
            }
            //hallar el minimo con el nuemro de ciclos y fin.

            if(res > 0)++res;
            System.out.println(res);
        }
    }
}


import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int test_case = scanner.nextInt();

            for(int i = 0; i < test_case; ++i)
            {
                int n = scanner.nextInt();
                int k = scanner.nextInt();
                HashMap<Integer,Integer> hm = new HashMap<>();
                int res = 0;
                int max_value = 0;
                int max_k = 0;

                int[] mod = new int[k];
                for(int j = 0; j < n; ++j)
                {
                    int temp = scanner.nextInt();
                    temp %= k;

                    int value = 0;
                    if(temp != 0){

                       mod[temp]++;
                       value = mod[temp];
                            if(value > max_value)
                            {
                             max_value = value;
                             max_k = k-temp;
                            }
                            else if(value == max_value) max_k = Math.max(max_k, k-temp);
                    }
                }

                if(max_value > 1)
                {
                    res = ((max_value-1)*k) + (max_k);

                }
                else if(max_value == 1)
                {
                    res = max_k;

                }
                //hallar el minimo con el nuemro de ciclos y fin.

                if(res > 0)++res;
                System.out.println(res);
            }
    }
}
// 2 1 1 2 3 1 5 4 2 3


import java.io.*;
import java.util.*;
import javafx.util.Pair;
import java.math.*;
import java.math.BigInteger;
import java.util.LinkedList;
import java.util.Queue;
public final  class CodeForces
{
    static StringBuilder ans=new StringBuilder();
    static FastReader in=new FastReader();
    static ArrayList<ArrayList<Integer>> g;
    static long mod=1000000007;
    static boolean set[];
    static Pair<Integer,Integer> seg[];
    static int A[];
    public static void main(String args[])throws IOException
    {
        int T=i();
        while(T-->0)
        {
            int N=i();
            long K=l();
            HashMap<Long,Integer> mp=new HashMap<>();
            boolean f=true;
            for(int i=0; i<N; i++)
            {
                long a=l();
                if(a%K!=0)
                {
                    f=false;
                    a=K-a%K;
                    if(mp.containsKey(a))
                    {
                        mp.put(a,mp.get(a)+1);
                    }
                    else mp.put(a,1);
                }
            }
            long key=0,freq=0;
            long max=0,mf=0;
            for(Map.Entry<Long,Integer> entry: mp.entrySet())
            {
                key=entry.getKey();
                freq=entry.getValue();
                if(mf==freq)
                {
                    max=key;
                }
                if(freq>mf)
                {
                    mf=freq;
                    max=key;
                }
            }
            if(!f)
            System.out.println((mf-1)*K+max+1);
            else System.out.println(0);
        }
    }

    static void sort(long[] a) //check for long
    {
        ArrayList<Long> l=new ArrayList<>();
        for (long i:a) l.add(i);
        Collections.sort(l);
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }

    static String swap(String X,int i,int j)
    {
        char ch[]=X.toCharArray();
        char a=ch[i];
        ch[i]=ch[j];
        ch[j]=a;
        return new String(ch);
    }

    static int sD(long n)
    {

        if (n % 2 == 0 )
            return 2;

        for (int i = 3; i * i <= n; i += 2) {
            if (n % i == 0 )
                return i;
        }

        return (int)n;
    }

    static void setGraph(int N)
    {
        set=new boolean[N+1];
        g=new ArrayList<ArrayList<Integer>>();
        for(int i=0; i<=N; i++)
            g.add(new ArrayList<Integer>());
    }

    static void DFS(int N,int d)
    {
        set[N]=true;
        d++;
        for(int i=0; i<g.get(N).size(); i++)
        {
            int c=g.get(N).get(i);
            if(set[c]==false)
            {
                DFS(c,d);
            }
        }
    }

    static  long pow(long a,long b)
    {
        long mod=1000000007;
        long pow=1;
        long x=a;
        while(b!=0)
        {
            if((b&1)!=0)pow=(pow*x)%mod;
            x=(x*x)%mod;
            b/=2;
        }
        return pow;
    }

    static long toggleBits(long x)//one's complement || Toggle bits
    {
        int n=(int)(Math.floor(Math.log(x)/Math.log(2)))+1;

        return ((1<<n)-1)^x;
    }

    static int countBits(long a)
    {
        return (int)(Math.log(a)/Math.log(2)+1);
    }

    static long fact(long N)
    {
        long n=2;
        if(N<=1)return 1;
        else
        {
            for(int i=3; i<=N; i++)n=(n*i)%mod;
        }
        return n;
    }

    static int kadane(int A[])
    {
        int lsum=A[0],gsum=A[0];
        for(int i=1; i<A.length; i++)
        {
            lsum=Math.max(lsum+A[i],A[i]);
            gsum=Math.max(gsum,lsum);
        }
        return gsum;
    }

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

    static boolean isPrime(long N)
    {
        if (N<=1)  return false;
        if (N<=3)  return true;
        if (N%2 == 0 || N%3 == 0) return false;
        for (int i=5; i*i<=N; i=i+6)
            if (N%i == 0 || N%(i+2) == 0)
                return false;
        return true;
    }

    static int i()
    {
        return in.nextInt();
    }

    static long l()
    {
        return in.nextLong();
    }

    static int[] input(int N){
        int A[]=new int[N];
        for(int i=0; i<N; i++)
        {
            A[i]=in.nextInt();
        }
        return A;
    }

    static long[] inputLong(int N)     {
        long A[]=new long[N];
        for(int i=0; i<A.length; i++)A[i]=in.nextLong();
        return A;
    }

    static long GCD(long a,long b)
    {
        if(b==0)
        {
            return a;
        }
        else return GCD(b,a%b );
    }

}
//Code For FastReader
//Code For FastReader
//Code For FastReader
//Code For FastReader
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.*;
import java.util.*;
import javafx.util.Pair;
import java.math.*;
import java.math.BigInteger;
import java.util.LinkedList;
import java.util.Queue;
public final  class CodeForces
{
    static StringBuilder ans=new StringBuilder();
    static FastReader in=new FastReader();
    static ArrayList<ArrayList<Integer>> g;
    static long mod=1000000007;
    static boolean set[];
    static Pair<Integer,Integer> seg[];
    static int A[];
    public static void main(String args[])throws IOException
    {
        int T=i();
        while(T-->0)
        {
            int N=i();
            long K=l();
            HashMap<Long,Integer> mp=new HashMap<>();
            boolean f=true;
            for(int i=0; i<N; i++)
            {
                long a=l();
                if(a%K!=0)
                {
                    f=false;
                    a=K-a%K;
                    if(mp.containsKey(a))
                    {
                        mp.put(a,mp.get(a)+1);
                    }
                    else mp.put(a,1);
                }
            }
            long key=0,freq=0;
            long max=0,mf=0;
            for(Map.Entry<Long,Integer> entry: mp.entrySet())
            {
                key=entry.getKey();
                freq=entry.getValue();
                if(mf==freq)
                {
                    max=key;
                }
                if(freq>mf)
                {
                    mf=freq;
                    max=key;
                }
            }
            if(f)
            System.out.println((mf-1)*K+max+1);
            else System.out.println(0);
        }
    }

    static void sort(long[] a) //check for long
    {
        ArrayList<Long> l=new ArrayList<>();
        for (long i:a) l.add(i);
        Collections.sort(l);
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }

    static String swap(String X,int i,int j)
    {
        char ch[]=X.toCharArray();
        char a=ch[i];
        ch[i]=ch[j];
        ch[j]=a;
        return new String(ch);
    }

    static int sD(long n)
    {

        if (n % 2 == 0 )
            return 2;

        for (int i = 3; i * i <= n; i += 2) {
            if (n % i == 0 )
                return i;
        }

        return (int)n;
    }

    static void setGraph(int N)
    {
        set=new boolean[N+1];
        g=new ArrayList<ArrayList<Integer>>();
        for(int i=0; i<=N; i++)
            g.add(new ArrayList<Integer>());
    }

    static void DFS(int N,int d)
    {
        set[N]=true;
        d++;
        for(int i=0; i<g.get(N).size(); i++)
        {
            int c=g.get(N).get(i);
            if(set[c]==false)
            {
                DFS(c,d);
            }
        }
    }

    static  long pow(long a,long b)
    {
        long mod=1000000007;
        long pow=1;
        long x=a;
        while(b!=0)
        {
            if((b&1)!=0)pow=(pow*x)%mod;
            x=(x*x)%mod;
            b/=2;
        }
        return pow;
    }

    static long toggleBits(long x)//one's complement || Toggle bits
    {
        int n=(int)(Math.floor(Math.log(x)/Math.log(2)))+1;

        return ((1<<n)-1)^x;
    }

    static int countBits(long a)
    {
        return (int)(Math.log(a)/Math.log(2)+1);
    }

    static long fact(long N)
    {
        long n=2;
        if(N<=1)return 1;
        else
        {
            for(int i=3; i<=N; i++)n=(n*i)%mod;
        }
        return n;
    }

    static int kadane(int A[])
    {
        int lsum=A[0],gsum=A[0];
        for(int i=1; i<A.length; i++)
        {
            lsum=Math.max(lsum+A[i],A[i]);
            gsum=Math.max(gsum,lsum);
        }
        return gsum;
    }

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

    static boolean isPrime(long N)
    {
        if (N<=1)  return false;
        if (N<=3)  return true;
        if (N%2 == 0 || N%3 == 0) return false;
        for (int i=5; i*i<=N; i=i+6)
            if (N%i == 0 || N%(i+2) == 0)
                return false;
        return true;
    }

    static int i()
    {
        return in.nextInt();
    }

    static long l()
    {
        return in.nextLong();
    }

    static int[] input(int N){
        int A[]=new int[N];
        for(int i=0; i<N; i++)
        {
            A[i]=in.nextInt();
        }
        return A;
    }

    static long[] inputLong(int N)     {
        long A[]=new long[N];
        for(int i=0; i<A.length; i++)A[i]=in.nextLong();
        return A;
    }

    static long GCD(long a,long b)
    {
        if(b==0)
        {
            return a;
        }
        else return GCD(b,a%b );
    }

}
//Code For FastReader
//Code For FastReader
//Code For FastReader
//Code For FastReader
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.*;
import java.util.*;
import javafx.util.Pair;
import java.math.*;
import java.math.BigInteger;
import java.util.LinkedList;
import java.util.Queue;
public final  class CodeForces
{
    static StringBuilder ans=new StringBuilder();
    static FastReader in=new FastReader();
    static ArrayList<ArrayList<Integer>> g;
    static long mod=1000000007;
    static boolean set[];
    static Pair<Integer,Integer> seg[];
    static int A[];
    public static void main(String args[])throws IOException
    {
        int T=i();
        while(T-->0)
        {
            int N=i();
            long K=l();
            HashMap<Long,Integer> mp=new HashMap<>();
            boolean f=true;
            for(int i=0; i<N; i++)
            {
                long a=l();
                if(a%K!=0)
                {
                    f=false;
                    a=K-a%K;
                    if(mp.containsKey(a))
                    {
                        mp.put(a,mp.get(a)+1);
                    }
                    else mp.put(a,1);
                }
            }
            long key=0,freq=0;
            long max=0,mf=0;
            for(Map.Entry<Long,Integer> entry: mp.entrySet())
            {
                key=entry.getKey();
                freq=entry.getValue();
                if(mf==freq)
                {
                    max=key;
                }
                if(freq>mf)
                {
                    mf=freq;
                    max=key;
                }
            }
            System.out.println((mf-1)*K+max);
        }
    }

    static void sort(long[] a) //check for long
    {
        ArrayList<Long> l=new ArrayList<>();
        for (long i:a) l.add(i);
        Collections.sort(l);
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }

    static String swap(String X,int i,int j)
    {
        char ch[]=X.toCharArray();
        char a=ch[i];
        ch[i]=ch[j];
        ch[j]=a;
        return new String(ch);
    }

    static int sD(long n)
    {

        if (n % 2 == 0 )
            return 2;

        for (int i = 3; i * i <= n; i += 2) {
            if (n % i == 0 )
                return i;
        }

        return (int)n;
    }

    static void setGraph(int N)
    {
        set=new boolean[N+1];
        g=new ArrayList<ArrayList<Integer>>();
        for(int i=0; i<=N; i++)
            g.add(new ArrayList<Integer>());
    }

    static void DFS(int N,int d)
    {
        set[N]=true;
        d++;
        for(int i=0; i<g.get(N).size(); i++)
        {
            int c=g.get(N).get(i);
            if(set[c]==false)
            {
                DFS(c,d);
            }
        }
    }

    static  long pow(long a,long b)
    {
        long mod=1000000007;
        long pow=1;
        long x=a;
        while(b!=0)
        {
            if((b&1)!=0)pow=(pow*x)%mod;
            x=(x*x)%mod;
            b/=2;
        }
        return pow;
    }

    static long toggleBits(long x)//one's complement || Toggle bits
    {
        int n=(int)(Math.floor(Math.log(x)/Math.log(2)))+1;

        return ((1<<n)-1)^x;
    }

    static int countBits(long a)
    {
        return (int)(Math.log(a)/Math.log(2)+1);
    }

    static long fact(long N)
    {
        long n=2;
        if(N<=1)return 1;
        else
        {
            for(int i=3; i<=N; i++)n=(n*i)%mod;
        }
        return n;
    }

    static int kadane(int A[])
    {
        int lsum=A[0],gsum=A[0];
        for(int i=1; i<A.length; i++)
        {
            lsum=Math.max(lsum+A[i],A[i]);
            gsum=Math.max(gsum,lsum);
        }
        return gsum;
    }

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

    static boolean isPrime(long N)
    {
        if (N<=1)  return false;
        if (N<=3)  return true;
        if (N%2 == 0 || N%3 == 0) return false;
        for (int i=5; i*i<=N; i=i+6)
            if (N%i == 0 || N%(i+2) == 0)
                return false;
        return true;
    }

    static int i()
    {
        return in.nextInt();
    }

    static long l()
    {
        return in.nextLong();
    }

    static int[] input(int N){
        int A[]=new int[N];
        for(int i=0; i<N; i++)
        {
            A[i]=in.nextInt();
        }
        return A;
    }

    static long[] inputLong(int N)     {
        long A[]=new long[N];
        for(int i=0; i<A.length; i++)A[i]=in.nextLong();
        return A;
    }

    static long GCD(long a,long b)
    {
        if(b==0)
        {
            return a;
        }
        else return GCD(b,a%b );
    }

}
//Code For FastReader
//Code For FastReader
//Code For FastReader
//Code For FastReader
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.*;
import java.util.*;
import javafx.util.Pair;
import java.math.*;
import java.math.BigInteger;
import java.util.LinkedList;
import java.util.Queue;
public final  class CodeForces
{
    static StringBuilder ans=new StringBuilder();
    static FastReader in=new FastReader();
    static ArrayList<ArrayList<Integer>> g;
    static long mod=1000000007;
    static boolean set[];
    static Pair<Integer,Integer> seg[];
    static int A[];
    public static void main(String args[])throws IOException
    {
        int T=i();
        while(T-->0)
        {
            int N=i();
            long K=l();
            HashMap<Long,Integer> mp=new HashMap<>();
            boolean f=true;
            for(int i=0; i<N; i++)
            {
                long a=l();
                if(a%K!=0)
                {
                    f=false;
                    a=K-a%K;
                    if(mp.containsKey(a))
                    {
                        mp.put(a,mp.get(a)+1);
                    }
                    else mp.put(a,1);
                }
            }
            long key=0,freq=0;
            long max=0,mf=0;
            for(Map.Entry<Long,Integer> entry: mp.entrySet())
            {
                key=entry.getKey();
                freq=entry.getValue();
                if(mf==freq)
                {
                    max=Math.max(key,max);
                }
                if(freq>mf)
                {
                    mf=freq;
                    max=key;
                }
            }
            if(!f)
            System.out.println((mf-1)*K+max+1);
            else System.out.println(0);
        }
    }

    static void sort(long[] a) //check for long
    {
        ArrayList<Long> l=new ArrayList<>();
        for (long i:a) l.add(i);
        Collections.sort(l);
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }

    static String swap(String X,int i,int j)
    {
        char ch[]=X.toCharArray();
        char a=ch[i];
        ch[i]=ch[j];
        ch[j]=a;
        return new String(ch);
    }

    static int sD(long n)
    {

        if (n % 2 == 0 )
            return 2;

        for (int i = 3; i * i <= n; i += 2) {
            if (n % i == 0 )
                return i;
        }

        return (int)n;
    }

    static void setGraph(int N)
    {
        set=new boolean[N+1];
        g=new ArrayList<ArrayList<Integer>>();
        for(int i=0; i<=N; i++)
            g.add(new ArrayList<Integer>());
    }

    static void DFS(int N,int d)
    {
        set[N]=true;
        d++;
        for(int i=0; i<g.get(N).size(); i++)
        {
            int c=g.get(N).get(i);
            if(set[c]==false)
            {
                DFS(c,d);
            }
        }
    }

    static  long pow(long a,long b)
    {
        long mod=1000000007;
        long pow=1;
        long x=a;
        while(b!=0)
        {
            if((b&1)!=0)pow=(pow*x)%mod;
            x=(x*x)%mod;
            b/=2;
        }
        return pow;
    }

    static long toggleBits(long x)//one's complement || Toggle bits
    {
        int n=(int)(Math.floor(Math.log(x)/Math.log(2)))+1;

        return ((1<<n)-1)^x;
    }

    static int countBits(long a)
    {
        return (int)(Math.log(a)/Math.log(2)+1);
    }

    static long fact(long N)
    {
        long n=2;
        if(N<=1)return 1;
        else
        {
            for(int i=3; i<=N; i++)n=(n*i)%mod;
        }
        return n;
    }

    static int kadane(int A[])
    {
        int lsum=A[0],gsum=A[0];
        for(int i=1; i<A.length; i++)
        {
            lsum=Math.max(lsum+A[i],A[i]);
            gsum=Math.max(gsum,lsum);
        }
        return gsum;
    }

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

    static boolean isPrime(long N)
    {
        if (N<=1)  return false;
        if (N<=3)  return true;
        if (N%2 == 0 || N%3 == 0) return false;
        for (int i=5; i*i<=N; i=i+6)
            if (N%i == 0 || N%(i+2) == 0)
                return false;
        return true;
    }

    static int i()
    {
        return in.nextInt();
    }

    static long l()
    {
        return in.nextLong();
    }

    static int[] input(int N){
        int A[]=new int[N];
        for(int i=0; i<N; i++)
        {
            A[i]=in.nextInt();
        }
        return A;
    }

    static long[] inputLong(int N)     {
        long A[]=new long[N];
        for(int i=0; i<A.length; i++)A[i]=in.nextLong();
        return A;
    }

    static long GCD(long a,long b)
    {
        if(b==0)
        {
            return a;
        }
        else return GCD(b,a%b );
    }

}
//Code For FastReader
//Code For FastReader
//Code For FastReader
//Code For FastReader
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.*;
import java.lang.reflect.Array;
import java.util.*;

public class D {
    static 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;
        }
    }

    static FastReader s = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    private static int[] rai(int n) {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextInt();
        }
        return arr;
    }

    private static int[][] rai(int n, int m) {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextInt();
            }
        }
        return arr;
    }

    private static long[] ral(int n) {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextLong();
        }
        return arr;
    }

    private static long[][] ral(int n, int m) {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextLong();
            }
        }
        return arr;
    }

    private static int ri() {
        return s.nextInt();
    }

    private static long rl() {
        return s.nextLong();
    }

    private static String rs() {
        return s.next();
    }

    static int gcd(int a, int b)
    {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }
    static boolean[] sieveOfEratosthenes(int n)
    {
        boolean[] prime = new boolean[n+1];
        for(int i=0;i<n;i++)
            prime[i] = true;

        for(int p = 2; p*p <=n; p++)
        {
            if(prime[p])
            {
                for(int i = p*p; i <= n; i += p)
                    prime[i] = false;
            }
        }

        return prime;
    }
    public static int[] lowestPrimeFactors(int n) {
        int tot = 0;
        int[] lpf = new int[n + 1];
        int u = n + 32;
        double lu = Math.log(u);
        int[] primes = new int[(int) (u / lu + u / lu / lu * 1.5)];
        for (int i = 2; i <= n; i++)
            lpf[i] = i;
        for (int p = 2; p <= n; p++) {
            if (lpf[p] == p)
                primes[tot++] = p;
            int tmp;
            for (int i = 0; i < tot && primes[i] <= lpf[p] && (tmp = primes[i] * p) <= n; i++) {
                lpf[tmp] = primes[i];
            }
        }
        return lpf;
    }
    static int bsearch(List<Integer> list,int x)
    {
        int l=0,r=list.size()-1;
        while(l<=r)
        {
            int mid=(l+r)/2;
            if(list.get(mid)>=x)
            {
                if(mid==0)
                {
                    return mid;
                }
                else if(list.get(mid-1)<x)
                {
                    return mid;
                }
                else {
                    r=mid-1;
                }
            }
            else
            {
                l=mid+1;
            }
        }
        return -1;
    }
    public static void main(String[] args) {
        StringBuilder ans = new StringBuilder();
        int t = ri();
//        int t= 1;
        while (t-- > 0)
        {
            int n=ri();int k=ri();
            int[] arr=rai(n);
//            int[] dp=new int[k];

            TreeMap<Integer,Integer> map=new TreeMap<>();
            for(int i:arr)
            {
                int val=i%k;
                if(val!=0)
                {
                    val=k-val;
                    map.put(val,map.getOrDefault(val,0)+1);
                }
            }
            int x=0;
            long count=0;
            while(map.size()>0)
            {
                List<Integer> list=new ArrayList<>(map.keySet());
                int ind=bsearch(list,x);
                if(ind==-1)
                {
                    count+=k-x;
                    x=k;
                    x%=k;
                    continue;
                }
                int val=list.get(ind);

//                System.out.println(x+" "+val);
                count+=val-x;
                map.put(val,map.getOrDefault(val,0)-1);
                count++;
                x=val;
                x+=1;
                if(map.get(val)<=0)
                {
                    map.remove(val);
                }
                x%=k;
//                System.out.println(x);
            }

            ans.append(count).append("\n");

        }
        out.print(ans.toString());
        out.flush();

    }
}


import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class D {
    static 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;
        }
    }

    static FastReader s = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    private static int[] rai(int n) {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextInt();
        }
        return arr;
    }

    private static int[][] rai(int n, int m) {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextInt();
            }
        }
        return arr;
    }

    private static long[] ral(int n) {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextLong();
        }
        return arr;
    }

    private static long[][] ral(int n, int m) {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextLong();
            }
        }
        return arr;
    }

    private static int ri() {
        return s.nextInt();
    }

    private static long rl() {
        return s.nextLong();
    }

    private static String rs() {
        return s.next();
    }

    static int gcd(int a, int b)
    {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }
    static boolean[] sieveOfEratosthenes(int n)
    {
        boolean[] prime = new boolean[n+1];
        for(int i=0;i<n;i++)
            prime[i] = true;

        for(int p = 2; p*p <=n; p++)
        {
            if(prime[p])
            {
                for(int i = p*p; i <= n; i += p)
                    prime[i] = false;
            }
        }

        return prime;
    }
    public static int[] lowestPrimeFactors(int n) {
        int tot = 0;
        int[] lpf = new int[n + 1];
        int u = n + 32;
        double lu = Math.log(u);
        int[] primes = new int[(int) (u / lu + u / lu / lu * 1.5)];
        for (int i = 2; i <= n; i++)
            lpf[i] = i;
        for (int p = 2; p <= n; p++) {
            if (lpf[p] == p)
                primes[tot++] = p;
            int tmp;
            for (int i = 0; i < tot && primes[i] <= lpf[p] && (tmp = primes[i] * p) <= n; i++) {
                lpf[tmp] = primes[i];
            }
        }
        return lpf;
    }
    public static void main(String[] args) {
        StringBuilder ans = new StringBuilder();
        int t = ri();
//        int t= 1;
        while (t-- > 0)
        {
            int n=ri();int k=ri();
            int[] arr=rai(n);
            int[] dp=new int[k];

            TreeMap<Integer,Integer> map=new TreeMap<>();
            for(int i:arr)
            {
                int val=i%k;
                if(val!=0)
                {
                    val=k-val;
                    map.put(val,map.getOrDefault(val,0)+1);
                }
            }
            int x=0;
            long count=0;
            while(map.size()>0)
            {
                Integer val=map.higherKey(x);
                if(map.containsKey(x))
                {
                    val=x;
                }
                else if(val==null)
                {
                    count++;
                    x++;
                    x%=k;
                    continue;
                }

//                System.out.println(x+" "+val);
                count+=val-x;
                map.put(val,map.getOrDefault(val,0)-1);
                count++;
                x=val;
                x+=1;
                if(map.get(val)<=0)
                {
                    map.remove(val);
                }
                x%=k;
//                System.out.println(x);
            }

            ans.append(count).append("\n");

        }
        out.print(ans.toString());
        out.flush();

    }
}


import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class D {
    static 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;
        }
    }

    static FastReader s = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    private static int[] rai(int n) {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextInt();
        }
        return arr;
    }

    private static int[][] rai(int n, int m) {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextInt();
            }
        }
        return arr;
    }

    private static long[] ral(int n) {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextLong();
        }
        return arr;
    }

    private static long[][] ral(int n, int m) {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextLong();
            }
        }
        return arr;
    }

    private static int ri() {
        return s.nextInt();
    }

    private static long rl() {
        return s.nextLong();
    }

    private static String rs() {
        return s.next();
    }

    static int gcd(int a, int b)
    {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }
    static boolean[] sieveOfEratosthenes(int n)
    {
        boolean[] prime = new boolean[n+1];
        for(int i=0;i<n;i++)
            prime[i] = true;

        for(int p = 2; p*p <=n; p++)
        {
            if(prime[p])
            {
                for(int i = p*p; i <= n; i += p)
                    prime[i] = false;
            }
        }

        return prime;
    }
    public static int[] lowestPrimeFactors(int n) {
        int tot = 0;
        int[] lpf = new int[n + 1];
        int u = n + 32;
        double lu = Math.log(u);
        int[] primes = new int[(int) (u / lu + u / lu / lu * 1.5)];
        for (int i = 2; i <= n; i++)
            lpf[i] = i;
        for (int p = 2; p <= n; p++) {
            if (lpf[p] == p)
                primes[tot++] = p;
            int tmp;
            for (int i = 0; i < tot && primes[i] <= lpf[p] && (tmp = primes[i] * p) <= n; i++) {
                lpf[tmp] = primes[i];
            }
        }
        return lpf;
    }
    public static void main(String[] args) {
        StringBuilder ans = new StringBuilder();
        int t = ri();
//        int t= 1;
        while (t-- > 0)
        {
            int n=ri();int k=ri();
            int[] arr=rai(n);
//            int[] dp=new int[k];

            TreeMap<Integer,Integer> map=new TreeMap<>();
            for(int i:arr)
            {
                int val=i%k;
                if(val!=0)
                {
                    val=k-val;
                    map.put(val,map.getOrDefault(val,0)+1);
                }
            }
            int x=0;
            long count=0;
            while(map.size()>0)
            {
                Integer val=map.higherKey(x);
                if(map.containsKey(x))
                {
                    val=x;
                }
                else if(val==null)
                {
                    count++;
                    x++;
                    x%=k;
                    continue;
                }

//                System.out.println(x+" "+val);
                count+=val-x;
                map.put(val,map.getOrDefault(val,0)-1);
                count++;
                x=val;
                x+=1;
                if(map.get(val)<=0)
                {
                    map.remove(val);
                }
                x%=k;
//                System.out.println(x);
            }

            ans.append(count).append("\n");

        }
        out.print(ans.toString());
        out.flush();

    }
}


import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class D {
    static 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;
        }
    }

    static FastReader s = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    private static int[] rai(int n) {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextInt();
        }
        return arr;
    }

    private static int[][] rai(int n, int m) {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextInt();
            }
        }
        return arr;
    }

    private static long[] ral(int n) {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextLong();
        }
        return arr;
    }

    private static long[][] ral(int n, int m) {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextLong();
            }
        }
        return arr;
    }

    private static int ri() {
        return s.nextInt();
    }

    private static long rl() {
        return s.nextLong();
    }

    private static String rs() {
        return s.next();
    }

    static int gcd(int a, int b)
    {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }
    static boolean[] sieveOfEratosthenes(int n)
    {
        boolean[] prime = new boolean[n+1];
        for(int i=0;i<n;i++)
            prime[i] = true;

        for(int p = 2; p*p <=n; p++)
        {
            if(prime[p])
            {
                for(int i = p*p; i <= n; i += p)
                    prime[i] = false;
            }
        }

        return prime;
    }
    public static int[] lowestPrimeFactors(int n) {
        int tot = 0;
        int[] lpf = new int[n + 1];
        int u = n + 32;
        double lu = Math.log(u);
        int[] primes = new int[(int) (u / lu + u / lu / lu * 1.5)];
        for (int i = 2; i <= n; i++)
            lpf[i] = i;
        for (int p = 2; p <= n; p++) {
            if (lpf[p] == p)
                primes[tot++] = p;
            int tmp;
            for (int i = 0; i < tot && primes[i] <= lpf[p] && (tmp = primes[i] * p) <= n; i++) {
                lpf[tmp] = primes[i];
            }
        }
        return lpf;
    }
    public static void main(String[] args) {
        StringBuilder ans = new StringBuilder();
        int t = ri();
//        int t= 1;
        while (t-- > 0)
        {
            int n=ri();int k=ri();
            int[] arr=rai(n);
            int[] dp=new int[k];

            TreeMap<Integer,Integer> map=new TreeMap<>();
            for(int i:arr)
            {
                int val=i%k;
                if(val!=0)
                {
                    val=k-val;
                    map.put(val,map.getOrDefault(val,0)+1);
                }
            }
            int x=0;
            long count=0;
            while(map.size()>0)
            {
                Integer val=map.higherKey(x);
                if(val==null || map.containsKey(x))
                {
                    val=x;
                }
//                System.out.println(x+" "+val);
                count+=val-x;
                map.put(val,map.getOrDefault(val,0)-1);
                count++;
                x=val;
                x+=1;
                if(map.get(val)<=0)
                {
                    map.remove(val);
                }
                x%=k;
//                System.out.println(x);
            }

            ans.append(count).append("\n");

        }
        out.print(ans.toString());
        out.flush();

    }
}


import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class D {
    static 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;
        }
    }

    static FastReader s = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    private static int[] rai(int n) {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextInt();
        }
        return arr;
    }

    private static int[][] rai(int n, int m) {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextInt();
            }
        }
        return arr;
    }

    private static long[] ral(int n) {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextLong();
        }
        return arr;
    }

    private static long[][] ral(int n, int m) {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextLong();
            }
        }
        return arr;
    }

    private static int ri() {
        return s.nextInt();
    }

    private static long rl() {
        return s.nextLong();
    }

    private static String rs() {
        return s.next();
    }

    static int gcd(int a, int b)
    {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }
    static boolean[] sieveOfEratosthenes(int n)
    {
        boolean[] prime = new boolean[n+1];
        for(int i=0;i<n;i++)
            prime[i] = true;

        for(int p = 2; p*p <=n; p++)
        {
            if(prime[p])
            {
                for(int i = p*p; i <= n; i += p)
                    prime[i] = false;
            }
        }

        return prime;
    }
    public static int[] lowestPrimeFactors(int n) {
        int tot = 0;
        int[] lpf = new int[n + 1];
        int u = n + 32;
        double lu = Math.log(u);
        int[] primes = new int[(int) (u / lu + u / lu / lu * 1.5)];
        for (int i = 2; i <= n; i++)
            lpf[i] = i;
        for (int p = 2; p <= n; p++) {
            if (lpf[p] == p)
                primes[tot++] = p;
            int tmp;
            for (int i = 0; i < tot && primes[i] <= lpf[p] && (tmp = primes[i] * p) <= n; i++) {
                lpf[tmp] = primes[i];
            }
        }
        return lpf;
    }
    static int bsearch(List<Integer> list,int x)
    {
        int l=0,r=list.size()-1;
        while(l<=r)
        {
            int mid=(l+r)/2;
            if(list.get(mid)>=x)
            {
                if(mid==0)
                {
                    return mid;
                }
                else if(list.get(mid-1)<x)
                {
                    return mid;
                }
                else {
                    r=mid-1;
                }
            }
            else
            {
                l=mid+1;
            }
        }
        return -1;
    }
    public static void main(String[] args) {
        StringBuilder ans = new StringBuilder();
        int t = ri();
//        int t= 1;
        while (t-- > 0)
        {
            int n=ri();int k=ri();
            int[] arr=rai(n);
//            int[] dp=new int[k];

            TreeMap<Integer,Integer> map=new TreeMap<>();
            for(int i:arr)
            {
                int val=i%k;
                if(val!=0)
                {
                    val=k-val;
                    map.put(val,map.getOrDefault(val,0)+1);
                }
            }
            long max=Integer.MIN_VALUE;
            int val=0;
            for(int i:map.keySet())
            {
//                System.out.println(i+" "+map.get(i));
                if(map.get(i)>=max) {
                    max = Math.max(map.get(i), max);
                    val=i;
                }

            }
            long count=max*k;
            if(max==Integer.MIN_VALUE)
            {
                count=0;
                ans.append(count).append("\n");
            }
            else {

                ans.append(count-(k-val-1)).append("\n");
            }

        }
        out.print(ans.toString());
        out.flush();

    }
}


//package src;

import java.util.Scanner;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.StringBuilder;
import java.math.BigInteger;

public class idk {
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;

	public static void main(String args[]) {
		int t = scn.nextInt();

		while (t-- > 0)
		{	//Stack<Integer>stk=new Stack<Integer>();
			int n=scn.nextInt(),k=scn.nextInt();
			long arr[]=new long[n];
			boolean bl=true;
			for(int i=0;i<n;i++)
			{
				arr[i]=scn.nextLong();
			}
			for(int i=0;i<n;i++)
			{
				if(arr[i]%k!=0)
				{
					bl=false;
					break;
				}
			}
			if(bl)
				System.out.println("0");
			else
			{	HashMap<Long,Long>map=new HashMap<>();
				Arrays.parallelSort(arr);
				long ans=0,max=0,c=0;
				for(int i=0;i<n;i++)
				{
					if(arr[i]%k!=0)
					{
						if(map.containsKey(arr[i]%k))
						{
							map.put(arr[i]%k, map.get(arr[i]%k)+k);
							max=Math.max(max,map.get(arr[i]%k));
						}
						else
						{
							map.put(arr[i]%k, Math.abs(k-(arr[i]%k)));
							max=Math.max(max,Math.abs(k-arr[i]%k));
						}
					}

				}
				System.out.println(max+1);
			}

		}

	}
	public static boolean word(String arr[],String str,String ori,HashMap<String, Integer>map,int i,int j)
	{	if(j==str.length())
	{	//System.out.println(str);
		if(str.length()==0)
			return true;
		else
			return false;
	}

		String re=ori.substring(i,j);
		System.out.println(re);
		if(map.containsKey(re))
		{	String res=ori.substring(j);

			return word(arr, str,ori, map, j, j);
		}

			return word(arr, str,ori, map, i, j+1);

	}
	public static int decode(String str, int i, int[] memo) {
		if (i == 0) {
			return 1;
		}
		int ind = str.length() - i;
		if (str.charAt(ind) == '0')
			return 0;
		if (memo[i] != -1)
			return memo[i];
		int res = decode(str, i - 1, memo);
		if (i >= 2 && Integer.parseInt(str.substring(ind, ind + 2)) <= 26) {
			res += decode(str, i - 2, memo);
		}
		memo[i] = res;
		return res;
	}

	public static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	public static String factorial(int n) {
		BigInteger fac = new BigInteger("1");
		for (int i = 1; i <= n; i++) {
			fac = fac.multiply(BigInteger.valueOf(i));
		}
		return fac.toString();
	}

}

class pair {
	int a;
	int b;

	pair(int x, int y) {
		this.a = x;
		this.b = y;
	}
}

class sorting implements Comparator<pair> {

	@Override
	public int compare(pair o1, pair o2) {
		// TODO Auto-generated method stub
		int x=o1.a-o2.a,y=o1.b-o2.b;
		if(y==0)
		{
			if(x>=0)
				return -1;
				else
					return 1;
		}
		else if(y>0)
			return -1;
		else
			return 1;
	}

}


//package src;

import java.util.Scanner;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.StringBuilder;
import java.math.BigInteger;

public class idk {
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;

	public static void main(String args[]) {
		int t = scn.nextInt();

		while (t-- > 0)
		{	//Stack<Integer>stk=new Stack<Integer>();
			int n=scn.nextInt(),k=scn.nextInt();
			Long arr[]=new Long[n];
			boolean bl=true;
			for(int i=0;i<n;i++)
			{
				arr[i]=scn.nextLong();
			}
			for(int i=0;i<n;i++)
			{
				if(arr[i]%k!=0)
				{
					bl=false;
					break;
				}
			}
			if(bl)
				System.out.println("0");
			else
			{	HashMap<Long,Long>map=new HashMap<>();
				Arrays.parallelSort(arr);
				long ans=0,max=0,c=0;
				for(int i=0;i<n;i++)
				{
					if(arr[i]%k!=0)
					{
						if(map.containsKey(arr[i]%k))
						{
							map.put(arr[i]%k, map.get(arr[i]%k)+k);
							max=Math.max(max,map.get(arr[i]%k));
						}
						else
						{
							map.put(arr[i]%k, Math.abs(k-(arr[i]%k)));
							max=Math.max(max,Math.abs(k-arr[i]%k));
						}
					}

				}
				System.out.println(max+1);
			}

		}

	}
	public static boolean word(String arr[],String str,String ori,HashMap<String, Integer>map,int i,int j)
	{	if(j==str.length())
	{	//System.out.println(str);
		if(str.length()==0)
			return true;
		else
			return false;
	}

		String re=ori.substring(i,j);
		System.out.println(re);
		if(map.containsKey(re))
		{	String res=ori.substring(j);

			return word(arr, str,ori, map, j, j);
		}

			return word(arr, str,ori, map, i, j+1);

	}
	public static int decode(String str, int i, int[] memo) {
		if (i == 0) {
			return 1;
		}
		int ind = str.length() - i;
		if (str.charAt(ind) == '0')
			return 0;
		if (memo[i] != -1)
			return memo[i];
		int res = decode(str, i - 1, memo);
		if (i >= 2 && Integer.parseInt(str.substring(ind, ind + 2)) <= 26) {
			res += decode(str, i - 2, memo);
		}
		memo[i] = res;
		return res;
	}

	public static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	public static String factorial(int n) {
		BigInteger fac = new BigInteger("1");
		for (int i = 1; i <= n; i++) {
			fac = fac.multiply(BigInteger.valueOf(i));
		}
		return fac.toString();
	}

}

class pair {
	int a;
	int b;

	pair(int x, int y) {
		this.a = x;
		this.b = y;
	}
}

class sorting implements Comparator<pair> {

	@Override
	public int compare(pair o1, pair o2) {
		// TODO Auto-generated method stub
		int x=o1.a-o2.a,y=o1.b-o2.b;
		if(y==0)
		{
			if(x>=0)
				return -1;
				else
					return 1;
		}
		else if(y>0)
			return -1;
		else
			return 1;
	}

}


//package src;

import java.util.Scanner;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.StringBuilder;
import java.math.BigInteger;

public class idk {
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;

	public static void main(String args[]) {
		int t = scn.nextInt();

		while (t-- > 0)
		{	//Stack<Integer>stk=new Stack<Integer>();
			int n=scn.nextInt(),k=scn.nextInt(),arr[]=new int[n];
			boolean bl=true;
			for(int i=0;i<n;i++)
			{
				arr[i]=scn.nextInt();
			}
			for(int i=0;i<n;i++)
			{
				if(arr[i]%k!=0)
				{
					bl=false;
					break;
				}
			}
			if(bl)
				System.out.println("0");
			else
			{	HashMap<Integer,Integer>map=new HashMap<Integer, Integer>();
				Arrays.parallelSort(arr);
				long ans=0,max=0;
				for(int i=0;i<n;i++)
				{
					if(arr[i]%k!=0)
					{
						if(map.containsKey(arr[i]%k))
						{
							map.put(arr[i]%k, map.get(arr[i]%k)+k);

							max=Math.max(max,map.get(arr[i]%k));
						}
						else
						{
							map.put(arr[i]%k, k-(arr[i]%k));
							max=Math.max(max,arr[i]%k);
						}
					}
				}
				//System.out.println(map);
				System.out.println(max+1);
			}

		}

	}
	public static boolean word(String arr[],String str,String ori,HashMap<String, Integer>map,int i,int j)
	{	if(j==str.length())
	{	//System.out.println(str);
		if(str.length()==0)
			return true;
		else
			return false;
	}

		String re=ori.substring(i,j);
		System.out.println(re);
		if(map.containsKey(re))
		{	String res=ori.substring(j);

			return word(arr, str,ori, map, j, j);
		}

			return word(arr, str,ori, map, i, j+1);

	}
	public static int decode(String str, int i, int[] memo) {
		if (i == 0) {
			return 1;
		}
		int ind = str.length() - i;
		if (str.charAt(ind) == '0')
			return 0;
		if (memo[i] != -1)
			return memo[i];
		int res = decode(str, i - 1, memo);
		if (i >= 2 && Integer.parseInt(str.substring(ind, ind + 2)) <= 26) {
			res += decode(str, i - 2, memo);
		}
		memo[i] = res;
		return res;
	}

	public static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	public static String factorial(int n) {
		BigInteger fac = new BigInteger("1");
		for (int i = 1; i <= n; i++) {
			fac = fac.multiply(BigInteger.valueOf(i));
		}
		return fac.toString();
	}

}

class pair {
	int a;
	int b;

	pair(int x, int y) {
		this.a = x;
		this.b = y;
	}
}

class sorting implements Comparator<pair> {

	@Override
	public int compare(pair o1, pair o2) {
		// TODO Auto-generated method stub
		int x=o1.a-o2.a,y=o1.b-o2.b;
		if(y==0)
		{
			if(x>=0)
				return -1;
				else
					return 1;
		}
		else if(y>0)
			return -1;
		else
			return 1;
	}

}


//package src;

import java.util.Scanner;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.StringBuilder;
import java.math.BigInteger;

public class idk {
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;

	public static void main(String args[]) {
		int t = scn.nextInt();

		while (t-- > 0)
		{	//Stack<Integer>stk=new Stack<Integer>();
			int n=scn.nextInt(),k=scn.nextInt();
			Long arr[]=new Long[n];
			boolean bl=true;
			for(int i=0;i<n;i++)
			{
				arr[i]=scn.nextLong();
			}
			for(int i=0;i<n;i++)
			{
				if(arr[i]%k!=0)
				{
					bl=false;
					break;
				}
			}
			if(bl)
				System.out.println("0");
			else
			{	TreeMap<Long,Long>map=new TreeMap<>();
				Arrays.parallelSort(arr);
				long ans=0,max=0,c=0;
				for(int i=0;i<n;i++)
				{
					if(arr[i]%k!=0)
					{
						if(map.containsKey(arr[i]%k))
						{
							map.put(arr[i]%k, map.get(arr[i]%k)+k);
							max=Math.max(max,map.get(arr[i]%k));
						}
						else
						{
							map.put(arr[i]%k, Math.abs(k-(arr[i]%k)));
							max=Math.max(max,Math.abs(k-arr[i]%k));
						}
					}

				}
				System.out.println(max+1);
			}

		}

	}
	public static boolean word(String arr[],String str,String ori,HashMap<String, Integer>map,int i,int j)
	{	if(j==str.length())
	{	//System.out.println(str);
		if(str.length()==0)
			return true;
		else
			return false;
	}

		String re=ori.substring(i,j);
		System.out.println(re);
		if(map.containsKey(re))
		{	String res=ori.substring(j);

			return word(arr, str,ori, map, j, j);
		}

			return word(arr, str,ori, map, i, j+1);

	}
	public static int decode(String str, int i, int[] memo) {
		if (i == 0) {
			return 1;
		}
		int ind = str.length() - i;
		if (str.charAt(ind) == '0')
			return 0;
		if (memo[i] != -1)
			return memo[i];
		int res = decode(str, i - 1, memo);
		if (i >= 2 && Integer.parseInt(str.substring(ind, ind + 2)) <= 26) {
			res += decode(str, i - 2, memo);
		}
		memo[i] = res;
		return res;
	}

	public static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	public static String factorial(int n) {
		BigInteger fac = new BigInteger("1");
		for (int i = 1; i <= n; i++) {
			fac = fac.multiply(BigInteger.valueOf(i));
		}
		return fac.toString();
	}

}

class pair {
	int a;
	int b;

	pair(int x, int y) {
		this.a = x;
		this.b = y;
	}
}

class sorting implements Comparator<pair> {

	@Override
	public int compare(pair o1, pair o2) {
		// TODO Auto-generated method stub
		int x=o1.a-o2.a,y=o1.b-o2.b;
		if(y==0)
		{
			if(x>=0)
				return -1;
				else
					return 1;
		}
		else if(y>0)
			return -1;
		else
			return 1;
	}

}


#include <bits/stdc++.h>
using namespace std;

//may thang kia dung co doc code tao va xam nua
int main() {
	int pos[26], dp[26], ans = 10000000, n; bool exist = false;
	memset(pos, -1, sizeof(pos));
	memset(dp, 0, sizeof(dp));
	string s; cin >> s;
	for(int i = 0; i < s.length(); i++) {
		n = s[i] - 'a';
		if(pos[n] == -1) pos[n] = i;
		else {
			dp[n] = max(dp[n], i - pos[n]);
			pos[n] = i, exist = true;
		}
	}
	for(int i = 0; i < 26; i++) if(dp[i]) ans = min(ans, dp[i]);
	printf("%d", (exist ? ans : ((n+1)/2) + 1));
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int pos[26], ans = 10000000, n; bool exist = false;
	memset(pos, -1, sizeof(pos));
	string s; cin >> s;
	for(int i = 0; i < s.length(); i++) {
		n = s[i] - 'a';
		if(pos[n] == -1) pos[n] = i;
		else {
			ans = min(ans, i - pos[n]);
			pos[n] = i, exist = true;
		}
	}
	printf("%d", (exist ? ans : ((n+1)/2) + 1));
}


#include <bits/stdc++.h>
using namespace std;

//may thang kia dung co doc code tao va xam nua
int main() {
	int pos[26], dp[26], ans = 10000000, n; bool exist = false;
	memset(pos, -1, sizeof(pos));
	memset(dp, 0, sizeof(dp));
	string s; cin >> s;
	for(int i = 0; i < s.length(); i++) {
		n = s[i] - 'a';
		if(pos[n] == -1) pos[n] = i;
		else {
			dp[n] = max(dp[n], i - pos[n]);
			pos[n] = i, exist = true;
		}
	}
	for(int i = 0; i < 26; i++) if(dp[i]) ans = min(ans, dp[n]);
	printf("%d", (exist ? ans : ((n+1)/2) + 1));
}


#include <bits/stdc++.h>
using namespace std;

//may thang kia dung co doc code tao va xam nua
int main() {
	int pos[26], dp[26], ans = 10000000, n; bool exist = false;
	memset(pos, -1, sizeof(pos));
	memset(dp, 0, sizeof(dp));
	string s; cin >> s;
	for(int i = 0; i < s.length(); i++) {
		n = s[i] - 'a';
		if(pos[n] == -1) pos[n] = i, dp[n] = i + 1;
		else {
			dp[n] = max(dp[n], i - pos[n]);
			pos[n] = i, exist = true;
		}
	}
	for(int i = 0; i < 26; i++) if(dp[i]) ans = min(ans, max(dp[i], (int) s.length() - pos[i]));
	printf("%d", min(ans, ((int) s.length()/2) + 1));
}


#include <bits/stdc++.h>
using namespace std;

//may thang kia dung co doc code tao va xam nua
int main() {
	int pos[26], dp[26], ans = 10000000, n; bool exist = false;
	memset(pos, -1, sizeof(pos));
	memset(dp, 0, sizeof(dp));
	string s; cin >> s;
	for(int i = 0; i < s.length(); i++) {
		n = s[i] - 'a';
		if(pos[n] == -1) pos[n] = i;
		else {
			dp[n] = max(dp[n], i - pos[n]);
			pos[n] = i, exist = true;
		}
	}
	for(int i = 0; i < 26; i++) if(dp[i]) ans = min(ans, dp[i]);
	printf("%d", (exist ? ans : (s.length()/2) + 1));
}


#include <bits/stdc++.h>
using namespace std;

//may thang kia dung co doc code tao va xam nua
int main() {
	int pos[26], dp[26], ans = 10000000, n; bool exist = false;
	memset(pos, -1, sizeof(pos));
	memset(dp, 0, sizeof(dp));
	string s; cin >> s;
	for(int i = 0; i < s.length(); i++) {
		n = s[i] - 'a';
		if(pos[n] == -1) pos[n] = i;
		else {
			dp[n] = max(dp[n], i - pos[n]);
			pos[n] = i, exist = true;
		}
	}
	for(int i = 0; i < 26; i++) if(dp[i]) ans = min(ans, dp[i]);
	printf("%d", (exist ? ans : ((s.length()+1)/2) + 1));
}


#include <bits/stdc++.h>
using namespace std;
char str[1000005];
int vis[305];
int ans[305];
int main() {
    scanf("%s",str+1);
    int tmp=1e7;
    int len=strlen(str+1);
    //for(int i=0;i<300;i++) ans[i]=1e7;
    for(int i=1;i<=len;i++)
	{

		ans[str[i]]=max(ans[str[i]],i-vis[str[i]]);
		//printf("%c %d %d\n",str[i],i-vis[str[i]],ans[str[i]]);
		vis[str[i]]=i;
	}
	for(int i=0;i<=300;i++) if(ans[i])
	{
		ans[i]=max(ans[i],len+1-vis[i]);
		//printf("%c %d\n",i,ans[i]);
		tmp=min(tmp,ans[i]);
	}
	if(tmp==1e7)
	{
		tmp=len/2+1;
	}

	printf("%d\n",tmp);
    return 0;
}
//gfliflgfhhdkceacdljgkegmdlhcgkcmlelmbbbmdddgdeeljjhgbbffmemmmkhebgkhadkdajabcjkcgbkgbaeacdedlkklfech


#include <bits/stdc++.h>
using namespace std;
char str[1000005];
int vis[305];
int ans[305];
int main()
{
    scanf("%s",str+1);
    int tmp=1e7;
    int len=strlen(str+1);
    for(int i=1;i<=len;i++)
	{
		ans[str[i]]=max(ans[str[i]],i-vis[str[i]]);
		vis[str[i]]=i;
	}
	for(int i=0;i<=300;i++)
	if(ans[i])
	{
		ans[i]=max(ans[i],len+1-vis[i]);
		tmp=min(tmp,ans[i]);
	}
	printf("%d\n",tmp);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
char str[1000005];
int vis[305];
int ans[305];
int main() {
    scanf("%s",str);
    int tmp=1e7;
    int len=strlen(str);
    for(int i=0;i<300;i++) ans[i]=1e7;
    for(int i=0;i<len;i++)
	{
	    if(!vis[str[i]]) vis[str[i]]=i;
	    else
		{
			ans[str[i]]=max(ans[str[i]],i-vis[str[i]]);
			vis[str[i]]=i;
		}
	}
	for(int i=0;i<=300;i++) if(ans[i]) tmp=min(tmp,ans[i]);
	if(tmp==1e7)
	{
		tmp=len/2+1;
	}
	printf("%d\n",tmp);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
char str[1000005];
int vis[305];
int ans[305];
int main() {
    scanf("%s",str);
    int tmp=1e7;
    int len=strlen(str);
    //for(int i=0;i<300;i++) ans[i]=1e7;
    for(int i=0;i<len;i++)
	{
	    if(!vis[str[i]]) vis[str[i]]=i;
	    else
		{
			ans[str[i]]=max(ans[str[i]],i-vis[str[i]]);
			vis[str[i]]=i;
		}
	}
	for(int i=0;i<=300;i++) if(ans[i]) tmp=min(tmp,ans[i]);
	if(tmp==1e7)
	{
		tmp=len/2+1;
	}
	printf("%d\n",tmp);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
char str[1000005];
int vis[305];
int ans[305];
int main() {
    scanf("%s",str);
    int tmp=1e7;
    int len=strlen(str);
    for(int i=0;i<300;i++) ans[i]=1e7;
    for(int i=0;i<len;i++)
	{
	    if(!vis[str[i]]) vis[str[i]]=i;
	    else
		{
			ans[str[i]]=min(ans[str[i]],i-vis[str[i]]);
			vis[str[i]]=i;
		}
	}
	for(int i=0;i<=300;i++) if(ans[i]) tmp=min(tmp,ans[i]);
	if(tmp==1e7)
	{
		tmp=len/2+1;
	}
	printf("%d\n",tmp);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
char str[1000005];
int vis[305];
int ans[305];
int main() {
    scanf("%s",str);
    int tmp=1e7;
    int len=strlen(str);
    for(int i=0;i<300;i++) ans[i]=1e7;
    for(int i=0;i<len;i++)
	{
	    if(!vis[str[i]]) vis[str[i]]=i;
	    else
		{
			ans[str[i]]=min(ans[str[i]],i-vis[str[i]]);
			vis[str[i]]=i;
		}
	}
	for(int i=0;i<=300;i++) if(ans[i]) tmp=min(tmp,ans[i]);
	if(tmp==1e7)
	{
		tmp=n/2+1;
	}
	printf("%d\n",tmp);
    return 0;
}


// Codeforces Bless me.

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

#define loop(i, num)  for (int i = 0; i < num; i++)

using namespace std;

string s;

bool check(int l) {

    int letters[26];

    loop (i, 26) {

        letters[i] = 0;

    }

    loop (i, l) {

        ++letters[s[i] - 'a'];

    }

    for (int i = l; i < s.size(); i++) {

        if (letters[s[i] - 'a'] > 0) {

            ++letters[s[i] - 'a'];

        }

        if (letters[s[i - l] - 'a'] > 0) {

            --letters[s[i - l] - 'a'];

        }

    }

    loop (i, 26) {

        if (letters[i] > 0)  return 1;

    }

    return 0;

}

int main() {

    cin >> s;

    int l = 1, r = s.size() / 2 + 1, mid;

    while (l < r) {

        mid = (l + r) / 2;

        if (check(mid)) {

            r = mid;

        } else {

            l = mid + 1;

        }

    }

    cout << l << endl;

}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>

#define loop(i, num)  for (int i = 0; i < num; ++i)
#define l  first
#define r  second

using namespace std;

int ans = INT_MAX;

string s;

int main(){

    cin>>s;

    for (int i = 0; i <= 26; i++) {

        int res = 0, t = 0;

        for (int j = 0; j < s.size(); j++) {

            res = max(res, ++t);

            if (s[j] == i + 'a')  t = 0;

        }

        ans = min(ans, res);

    }

    cout << ans << endl;

    return 0;

}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>

#define loop(i, num)  for (int i = 0; i < num; ++i)
#define l  first
#define r  second

using namespace std;

int len, ans;

string s;

char m;

vector<pair<int, char>> c;

bool find(string data, char tag) {

    loop (i, data.size()) {

        if (data[i] == tag)  return 1;

    }

    return 0;

}

bool check(string data, int len) {

    for (int i = 0; i < data.size() - len + 1; i++) {

        if (!find(data.substr(i, len), m)) {

            return 0;

        }

    }

    return 1;

}

int main() {

    cin >> s;

    c.resize(26);

    len = (int) s.size() / 2 + 1;

    loop (i, 26) {

        c[i].first = 0;

        c[i].second = i + 'a';

    }

    loop (i, s.size()) {

        ++c[s[i] - 'a'].first;

    }

    sort(c.begin(), c.end());

    reverse(c.begin(), c.end());

//    cout << m << ' ' << len << endl;

    loop (i, c.size() / 2 + 1) {

        m = c[i].second;

        for (int j = 1; j < len; j++) {

            if (check(s, j)) {

                len = j;

                break;

            }

        }

    }

    cout << len << endl;

    return 0;

}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>

#define loop(i, num)  for (int i = 0; i < num; ++i)
#define l  first
#define r  second

using namespace std;

int len, ans;

string s;

char m;

vector<pair<int, char>> c;

bool find(string data, char tag) {

    loop (i, data.size()) {

        if (data[i] == tag)  return 1;

    }

    return 0;

}

bool check(string data, int len) {

    for (int i = 0; i < data.size() - len + 1; i++) {

        if (!find(data.substr(i, len), m)) {

            return 0;

        }

    }

    return 1;

}

int main() {

    cin >> s;

    c.resize(26);

    len = (int) s.size() / 2 + 1;

    loop (i, 26) {

        c[i].first = 0;

        c[i].second = i + 'a';

    }

    loop (i, s.size()) {

        ++c[s[i] - 'a'].first;

    }

    sort(c.begin(), c.end());

    reverse(c.begin(), c.end());

//    cout << m << ' ' << len << endl;

    loop (i, c.size()) {

        m = c[i].second;

        for (int j = 1; j < len; j++) {

            if (check(s, j)) {

                len = j;

                break;

            }

        }

    }

    cout << len << endl;

    return 0;

}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>

#define loop(i, num)  for (int i = 0; i < num; ++i)
#define l  first
#define r  second

using namespace std;

int len, ans;

string s;

char m;

vector<pair<int, char>> c;

bool find(string data, char tag) {

    loop (i, data.size()) {

        if (data[i] == tag)  return 1;

    }

    return 0;

}

bool check(string data, int len) {

    for (int i = 0; i < data.size() - len + 1; i++) {

        if (!find(data.substr(i, len), m)) {

            return 0;

        }

    }

    return 1;

}

int main() {

    cin >> s;

    c.resize(26);

    len = (int) s.size() / 2 + 1;

    loop (i, 26) {

        c[i].first = 0;

        c[i].second = i + 'a';

    }

    loop (i, s.size()) {

        ++c[s[i] - 'a'].first;

    }

    sort(c.begin(), c.end());

    reverse(c.begin(), c.end());

//    cout << m << ' ' << len << endl;

    loop (i, c.size()) {

        if (c[i].first == 1) {

            break;

        }

        m = c[i].second;

        for (int j = 1; j < len; j++) {

            if (check(s, j)) {

                len = j;

                break;

            }

        }

    }

    cout << len << endl;

    return 0;

}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>

#define loop(i, num)  for (int i = 0; i < num; ++i)
#define l  first
#define r  second

using namespace std;

int len, ans;

string s;

char m;

vector<pair<int, char>> c;

bool find(string data, char tag) {

    loop (i, data.size()) {

        if (data[i] == tag)  return 1;

    }

    return 0;

}

bool check(string data, int len) {

    for (int i = 0; i < data.size() - len + 1; i++) {

        if (!find(data.substr(i, len), m)) {

            return 0;

        }

    }

    return 1;

}

int main() {

    cin >> s;

    c.resize(26);

    len = (int) s.size() / 2 + 1;

    loop (i, 26) {

        c[i].first = 0;

        c[i].second = i + 'a';

    }

    loop (i, s.size()) {

        ++c[s[i] - 'a'].first;

    }

    sort(c.begin(), c.end());

    reverse(c.begin(), c.end());

    m = c[0].second;

//    cout << m << ' ' << len << endl;

    for (int i = 1; i < len; i++) {

        if (check(s, i)) {

            len = i;

            break;

        }

    }

    cout << len << endl;

    return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define debug(...)   printf( __VA_ARGS__ )
//#define debug(...)   /****nothing****/
#define pb push_back
#define mp make_pair
#define LL long long
#define mem(arr,val) memset(arr,val,sizeof(arr))

int n,pre[600],b,k[600];
char str[1234567];

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    while(cin>>str+1)
    {
        mem(pre,0);
        mem(k,0);

        for(int i=1; i<=strlen(str+1); i++)
        {
            k[str[i]]=max(k[str[i]], i-pre[str[i]]);
            pre[str[i]]=i;
        }

        int ans=INT_MAX;

        for(int i=1; i<=strlen(str+1); i++)
            ans=min(ans,k[str[i]]);

        cout<<ans<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define debug(...)   printf( __VA_ARGS__ )
//#define debug(...)   /****nothing****/
#define pb push_back
#define mp make_pair
#define LL long long
#define mem(arr,val) memset(arr,val,sizeof(arr))

int n,a[282][100007],b;
string str;
set<char> st;

bool check(int len,char ch)
{
    for(int i=0; i<=(int)str.size()-len; i++)
        if(i==0 && a[ch-'a'][len-1]==0)
            return 0;
        else if(i>0 && (a[ch-'a'][i+len-1]- a[ch-'a'][i-1])==0)
            return 0;

    return 1;

}

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    while(cin>>str)
    {
        mem(a,0);
        st.clear();

        for(int i=0; i<str.size(); i++)
            st.insert(str[i]), a[str[i]-'a'][i]=1;

        for(char ch: st)
        {
            for(int i=1; i<str.size(); i++)
                a[ch-'a'][i]+=a[ch-'a'][i-1];
//
//            cout<<ch<<": ";
//
//            for(int i=0; i<str.size(); i++)
//                cout<<a[ch-'a'][i]<<" ";
//
//            cout<<endl;
        }

        int ans=INT_MAX,siz=str.size();

        for(char ch: st)
        {
            int low=-1,high=siz+1;
            while(high-low>1)
            {
                int mid=(high+low)>>1;
                if(check(mid,ch))
                    high=mid;
                else
                    low=mid;
            }

            if(high!=siz+1)
                ans=min(ans,high);

//            cout<<ch<<" "<<high<<endl;
        }

        cout<<ans<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define debug(...)   printf( __VA_ARGS__ )
//#define debug(...)   /****nothing****/
#define pb push_back
#define mp make_pair
#define LL long long
#define mem(arr,val) memset(arr,val,sizeof(arr))

int n,pre[600],b,len[600];
char str[200000];

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    while(scanf("%s",str+1)==1)
    {
        mem(pre,0);
        mem(len,0);

//        printf("%s",str+1);
       int sz=strlen(str+1);

        for(int i=1; i<=sz; i++)
        {
            len[str[i]]=max(len[str[i]] , i-pre[str[i]]);
            pre[str[i]]=i;
        }

        for(int i=1; i<=sz; i++)
            len[str[i]]=max(len[str[i]] , sz+1-pre[str[i]]);

      int ans=INT_MAX;

      for(int i=1;i<=sz;i++)
        ans=min(ans,len[str[i]]);

        cout<<ans<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define debug(...)   printf( __VA_ARGS__ )
//#define debug(...)   /****nothing****/
#define pb push_back
#define mp make_pair
#define LL long long
#define mem(arr,val) memset(arr,val,sizeof(arr))

int n,pre[600],b,len[600];
char str[2000000];

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    while(scanf("%s",str+1))
    {
        mem(pre,0);
        mem(len,0);

//        printf("%s",str+1);
       int sz=strlen(str+1);

        for(int i=1; i<=sz; i++)
        {
            len[str[i]]=max(len[str[i]] , i-pre[str[i]]);
            pre[str[i]]=i;
        }

        for(int i=1; i<=sz; i++)
            len[str[i]]=max(len[str[i]] , sz+1-pre[str[i]]);

      int ans=INT_MAX;

      for(int i=1;i<=sz;i++)
        ans=min(ans,len[str[i]]);

        cout<<ans<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define debug(...)   printf( __VA_ARGS__ )
//#define debug(...)   /****nothing****/
#define pb push_back
#define mp make_pair
#define LL long long
#define mem(arr,val) memset(arr,val,sizeof(arr))

int n,pre[600],b,len[600];
char str[200000];

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    while(cin>>str+1)
    {
        mem(pre,0);
        mem(len,0);

        int sz=strlen(str+1);

        for(int i=1; i<=sz; i++)
        {
            len[str[i]]=max(len[str[i]], i-pre[str[i]]);
            pre[str[i]]=i;
        }

        for(int i=1; i<=sz; i++)
            len[str[i]]=max(len[str[i]], sz+1-pre[str[i]]);

        int ans=INT_MAX;

        for(int i=1; i<=sz; i++)
            ans=min(ans,len[str[i]]);

        cout<<ans<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define debug(...)   printf( __VA_ARGS__ )
//#define debug(...)   /****nothing****/
#define pb push_back
#define mp make_pair
#define LL long long
#define mem(arr,val) memset(arr,val,sizeof(arr))

int n,pre[600],b,k[600];
char str[1234567];

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    while(cin>>str+1)
    {
        mem(pre,0);
        mem(k,0);

        for(int i=1; i<=strlen(str+1); i++)
        {
            k[str[i]]=max(k[str[i]], i-pre[str[i]]);
            pre[str[i]]=i;
        }

        int ans=INT_MAX;

        for(int i=1; i<=strlen(str+1); i++)
            ans=min(ans,k[str[i]])

        cout<<ans<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define debug(...)   printf( __VA_ARGS__ )
//#define debug(...)   /****nothing****/
#define pb push_back
#define mp make_pair
#define LL long long
#define mem(arr,val) memset(arr,val,sizeof(arr))

int n,pre[600],b,len[600];
char str[200000];

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    while(scanf("%s",str+1))
    {
        mem(pre,0);
        mem(len,0);

//        printf("%s",str+1);
       int sz=strlen(str+1);

        for(int i=1; i<=sz; i++)
        {
            len[str[i]]=max(len[str[i]] , i-pre[str[i]]);
            pre[str[i]]=i;
        }

        for(int i=1; i<=sz; i++)
            len[str[i]]=max(len[str[i]] , sz+1-pre[str[i]]);

      int ans=INT_MAX;

      for(int i=1;i<=sz;i++)
        ans=min(ans,len[str[i]]);

        cout<<ans<<endl;

    }

    return 0;
}