Raspberries
You are given an array of integers $$$a_1, a_2, \ldots, a_n$$$ and a number $$$k$$$ ($$$2 \leq k \leq 5$$$). In one operation, you can do the following: Choose an index $$$1 \leq i \leq n$$$, Set $$$a_i = a_i + 1$$$.Find the minimum number of operations needed to make the product of all the numbers in the array $$$a_1 \cdot a_2 \cdot \ldots \cdot a_n$$$ divisible by $$$k$$$.
In the first test case, we need to choose the index $$$i = 2$$$ twice. After that, the array will be $$$a = [7, 5]$$$. The product of all the numbers in the array is $$$35$$$.In the fourth test case, the product of the numbers in the array is $$$120$$$, which is already divisible by $$$5$$$, so no operations are needed.In the eighth test case, we can perform two operations by choosing $$$i = 2$$$ and $$$i = 3$$$ in any order. After that, the array will be $$$a = [1, 6, 10]$$$. The product of the numbers in the array is $$$60$$$.
Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then follows the description of the test cases.The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \leq n \leq 10^5$$$, $$$2 \leq k \leq 5$$$) — the size of the array $$$a$$$ and the number $$$k$$$.The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10$$$).It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output the minimum number of operations needed to make the product of all the numbers in the array divisible by $$$k$$$.
def solu(lis, k):
    minamam = k
    for i in lis:
        if i % k == 0:
            return 0
        num = k - i % k
        if num < minamam:
            minamam = num
    return minamam
sol = []
for j in range(int(input())):
    (n, k) = map(int, input().split())
    lis = list(map(int, input().split()))
    if k == 2 or k == 4:
        even2 = 0
        even4 = 0
        c = 2
        for i in lis:
            if i % 2 == 0:
                even2 += 1
            if i % 4 == 0:
                even4 += 1
            if i % 4 == 3:
                c = 1
        if k == 2:
            if even2 >= 1 or even4 >= 1:
                sol.append(0)
            else:
                sol.append(1)
        elif even2 >= 2 or even4:
            sol.append(0)
        else:
            sol.append(min([2 - even2, c]))
    elif k == 3:
        sol.append(solu(lis, 3))
    else:
        sol.append(solu(lis, 5))
for i in sol:
    print(i)
sol = []
for j in range(int(input())):
    (n, k) = map(int, input().split())
    lis = list(map(int, input().split()))
    if k == 2 or k == 4:
        even2 = 0
        even4 = 0
        c = 2
        for i in lis:
            if i % 2 == 0:
                even2 += 1
            if i % 4 == 0:
                even4 += 1
            if i % 4 == 3:
                c = 1
        if k == 2:
            if even2 >= 1 or even4 >= 1:
                sol.append(0)
            else:
                sol.append(1)
        elif even2 >= 2 or even4:
            sol.append(0)
        else:
            sol.append(min([2 - even2, c]))
    elif k == 3:
        minamam = 3
        flag = 1
        for i in lis:
            if i % 3 == 0:
                sol.append(0)
                flag = 0
                break
            num = 3 - i % 3
            if num < minamam:
                minamam = num
        if flag:
            sol.append(minamam)
    else:
        minamam = 5
        flag = 1
        for i in lis:
            if i % 5 == 0:
                sol.append(0)
                flag = 0
                break
            num = 5 - i % 5
            if num < minamam:
                minamam = num
        if flag:
            sol.append(minamam)
for i in sol:
    print(i)
import sys
input = sys.stdin.readline

def inp():
    return int(input())

def inlt():
    obj = map(int, input().split())
    return list(obj)

def insr():
    s = input()
    return list(s[:len(s) - 1])

def invr():
    return map(int, input().split())
if __name__ == '__main__':
    t = inp()
    result = []
    for i in range(t):
        (n, k) = invr()
        data = inlt()
        if k != 4:
            delta = k
            for x in data:
                mod = x % k
                if mod == 0:
                    delta = 0
                    break
                exp = k - mod
                if exp < delta:
                    delta = k - mod
            result.append(delta)
        else:
            check = [x for x in data if x % k == 0]
            if len(check) > 0:
                poss = 0
            elif n < 2:
                mod = data[-1] % k
                poss = 0 if k - mod == k else k - mod
            else:
                cnt = len([True for x in data if x % 2 == 0])
                if cnt >= 2:
                    poss = 0
                else:
                    check = len([True for x in data if x % k == 3])
                    if check > 0:
                        poss = 1
                    else:
                        poss = max([0, 2 - cnt])
            result.append(poss)
    for i in result:
        print(i)