You are given an array $a$ consisting of $n$ positive integers.

Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations:  Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$).  Just increase $x$ by $1$ ($x := x + 1$). 

The first operation can be applied no more than once to each $i$ from $1$ to $n$.

Your task is to find the minimum number of moves required to obtain such an array that each its element is divisible by $k$ (the value $k$ is given).

You have to answer $t$ independent test cases. 


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow.

The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) — the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.

It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).


-----Output-----

For each test case, print the answer — the minimum number of moves required to obtain such an array that each its element is divisible by $k$.


-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8

Output
6
18
0
227
8



-----Note-----

Consider the first test case of the example:  $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$;  $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$;  $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$;  $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$;  $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$;  $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$;  $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array. 

Note that you can't add $x$ to the same element more than once.

Difficulty: MEDIUM
Tags: Sorting

Amortized analysis

Mathematics
Skill types: Sorting

Amortized analysis

Starter code:

Solutions:
from collections import defaultdict as dc
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	p = dc(int)
	m = 0
	a = 0
	b = 0
	for i in range(n):
		y = l[i] % k
		if y != 0:
			x = k - y
			p[x] += 1
	if len(p) == 0:
		print(0)
	else:
		m = 0
		for i in p.keys():
			m = max(m, (p[i] - 1) * k + i)
		print(m + 1)


list_ans = []
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	list1 = list(map(int, input().split()))
	dict1 = {}
	for x in list1:
		s = ((x - 1) // k + 1) * k - x
		if s != 0:
			if s not in dict1:
				dict1[s] = 1
			else:
				dict1[s] += 1
	a = 0
	b = 0
	for x in sorted(list(dict1.keys())):
		if dict1[x] >= a:
			a = dict1[x]
			b = x
	list_ans.append(max((a - 1) * k + b + 1, 0))
print(*list_ans, sep='\n')


from collections import Counter
import operator
for t in range(int(input())):
	(n, k) = [*map(int, input().split())]
	cnt = Counter([e % k for e in [*map(int, input().split())]])
	(mod, times) = (0, 0)
	for (key, v) in cnt.items():
		if key != 0:
			if v > times:
				mod = key
				times = v
			elif v == times:
				mod = min(mod, key)
	if mod == 0:
		print(0)
	else:
		print((times - 1) * k + (k - mod + 1))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	for i in range(n):
		arr[i] = k - arr[i] % k
		if arr[i] == k:
			arr[i] = 0
	counts = {}
	for i in arr:
		if i not in counts.keys():
			counts[i] = 1
		else:
			counts[i] += 1
	if 0 in counts.keys():
		del counts[0]
	if counts == {}:
		x = 0
	else:
		x = max(counts.values())
	if x == 0 or counts == []:
		print(0)
	else:
		key = list(counts.keys())
		key.sort()
		for i in key[::-1]:
			if counts[i] == x:
				print((x - 1) * k + i + 1)
				break


def zerorem(n, k, array):
	a = []
	for y in array:
		if y % k != 0:
			a.append(k - y % k)
	if a == []:
		return 0
	maxcount = None
	maxcountn = None
	dic = {}
	for x in a:
		if x in dic:
			dic[x] += 1
		else:
			dic[x] = 1
		if maxcount == None:
			maxcount = dic[x]
			maxcountn = x
		if dic[x] > maxcount:
			maxcount = dic[x]
			maxcountn = x
		elif dic[x] == maxcount:
			if maxcountn < x:
				maxcountn = x
	if maxcount == 1:
		return max(a) + 1
	else:
		return (maxcount - 1) * k + maxcountn + 1
t = int(input())
a = []
for i in range(t):
	(n, k) = list(map(int, input().split(' ')))
	array = list(map(int, input().split(' ')))
	a.append([n, k, array])
for x in a:
	print(zerorem(*x))


for _ in range(0, int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	rem_count = {}
	for i in range(len(a)):
		if a[i] % k != 0:
			target = k - a[i] % k
			rem_count[target] = rem_count.get(target, 0) + 1
	if len(rem_count) == 0:
		print(0)
		continue
	max = 0
	rem = 0
	for i in rem_count:
		if rem_count[i] > max:
			max = rem_count[i]
			rem = i
		elif rem_count[i] == max and i > rem:
			rem = i
	print((max - 1) * k + rem + 1)


tests = int(input())
for _ in range(tests):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	max1 = 0
	d1 = {}
	c = 0
	for i in range(n):
		v = k - arr[i] % k
		if arr[i] % k == 0:
			continue
		z = v - 1
		if z not in d1:
			d1[z] = 1
		else:
			v += k * d1[v - 1]
			d1[z] += 1
		if v > max1:
			max1 = v
	if max1 == 0:
		print(0)
	else:
		print(max1 + 1)


from sys import stdin, stdout, setrecursionlimit
t = int(stdin.readline())
for _ in range(t):
	(n, k) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	rem = {}
	for i in a:
		if i % k != 0:
			if k - i % k not in rem:
				rem[k - i % k] = 1
			else:
				rem[k - i % k] += 1
	if len(rem) == 0:
		print(0)
	else:
		res = []
		for (i, j) in rem.items():
			res.append(k * (j - 1) + i)
		print(max(res) + 1)


from sys import stdin, stdout
from math import ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
tc = ii1()
for _ in range(tc):
	(n, k) = iia()
	arr = iia()
	d = {}
	for i in arr:
		if i % k != 0:
			d.setdefault(k - i % k, [0])[0] += 1
	arr = set()
	for i in d:
		if i not in arr:
			arr.add(i)
			d[i][0] -= 1
		cur = i
		while d[i][0] > 0:
			cur += k
			if cur not in arr:
				arr.add(cur)
				d[i][0] -= 1
	if not len(arr):
		print(0)
	else:
		print(max(arr) + 1)


testcases = int(input())
for testcase in range(testcases):
	temparr = input()
	temparr = temparr.split()
	n = int(temparr[0])
	k = int(temparr[1])
	temparr = input()
	temparr = temparr.split()
	arr = []
	dicts = {}
	maxs = 0
	for i in temparr:
		i = int(i)
		if i % k == 0:
			continue
		if i < k:
			diff = k - i
			while True:
				if diff not in dicts:
					if diff > maxs:
						maxs = diff
					dicts[diff] = 1
					break
				else:
					times = dicts[diff]
					dicts[diff] += 1
					diff += k * times
		else:
			modulo = i % k
			diff = k - modulo
			while True:
				if diff not in dicts:
					if diff > maxs:
						maxs = diff
					dicts[diff] = 1
					break
				else:
					times = dicts[diff]
					dicts[diff] += 1
					diff += k * times
	if len(dicts) == 0:
		print(0)
		continue
	else:
		print(maxs + 1)


def solve():
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	used = {}
	ans = 0
	for i in a:
		if i % k != 0:
			if i % k in used:
				ans = max(ans, k * (used[i % k] + 1) - i % k + 1)
				used[i % k] += 1
			else:
				ans = max(ans, k - i % k + 1)
				used[i % k] = 1
	print(ans)
[solve() for i in range(int(input()))]


from sys import stdin, stdout
from collections import defaultdict, Counter, deque
for _ in range(int(stdin.readline())):
	(n, k) = map(int, stdin.readline().split())
	l = list(map(int, stdin.readline().split()))
	for e in range(n):
		l[e] %= k
	a = dict(Counter(l))
	s = 1000000001
	m = 0
	for (i, j) in a.items():
		if i == 0:
			continue
		if j > m:
			(m, s) = (j, i)
		elif j == m:
			(m, s) = (m, min(s, i))
	if s == 1000000001:
		print(0)
	else:
		print(k * (m - 1) + k - s + 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = [(k - a[i] % k) % k for i in range(n)]
	mx = {}
	mx[0] = -1
	for x in b:
		if x == 0:
			continue
		if x not in mx:
			mx[x] = x
		else:
			mx[x] += k
	print(max(mx.values()) + 1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
testcases = int(input())
for j in range(testcases):
	(n, k) = map(int, input().split())
	vals = list(map(int, input().split()))
	dict1 = {}
	for s in range(n):
		rem = vals[s] % k
		if rem != 0:
			if not rem in dict1:
				dict1[rem] = 1
			else:
				dict1[rem] += 1
	maxval = 0
	key = 0
	newy = [k for k in dict1.keys()]
	newy.sort()
	for s in newy:
		if dict1[s] > maxval and s != 0:
			maxval = dict1[s]
			key = s
	if maxval == 0:
		print(0)
	else:
		print((maxval - 1) * k + k + 1 - key)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(i) % k for i in input().split()]
	b = {}
	b[0] = 0
	for i in a:
		if i not in b.keys():
			b[i] = 1
		else:
			b[i] += 1
	mx = 0
	mx_ind = 0
	for i in b.keys():
		if i == 0:
			continue
		if b[i] > mx:
			mx = b[i]
			mx_ind = i
		if b[i] == mx and mx_ind > i:
			mx_ind = i
	if b[0] == n:
		print(0)
	else:
		print(k * (mx - 1) + k - mx_ind + 1)


import sys
input = sys.stdin.readline

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(10000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	(n, k) = int_array()
	a = int_array()
	dick = {}
	ans = 0
	for i in a:
		if i % k != 0:
			dick[k - i % k] = dick.get(k - i % k, 0) + 1
	for i in dick:
		ans = max(ans, k * (dick[i] - 1) + i + 1)
	print(ans)


from sys import stdin, stdout
import heapq as hq
from collections import defaultdict
t = int(input())
for tc in range(t):
	(n, k) = list(map(int, stdin.readline().split()))
	ar = list(map(int, stdin.readline().split()))
	dic = defaultdict(int)
	for val in ar:
		m = val % k
		if m > 0:
			dic[m] += 1
	res = 0
	undone = 0
	x = 0
	l = []
	for key in dic:
		l.append([k - key, dic[key]])
		undone += 1
	l = sorted(l, key=lambda x: x[0])
	while undone > 0:
		for tup in l:
			if tup[1] > 0:
				while tup[0] < x:
					tup[0] += k
				res += tup[0] - x
				x = tup[0]
				res += 1
				x += 1
				x %= k
				tup[1] -= 1
				if tup[1] == 0:
					undone -= 1
	stdout.write(str(res) + '\n')


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
from heapq import heapify, heappop, heappush, heappushpop, heapreplace

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline().rstrip()

def lsi():
	return list(si())
res = ['YES', 'NO']
test_case = ii()
while test_case:
	test_case -= 1
	(n, k) = mi()
	p = li()
	mx = 0
	s = set()
	d = dict()
	for i in p:
		x = i % k
		if x:
			x = k - x
			if x in d:
				d[x] += 1
			else:
				d[x] = 0
			x += k * d[x]
			while True:
				if x in s:
					x += k
				else:
					mx = max(mx, x)
					s.add(x)
					break
	print(mx + 1 if mx else 0)


from collections import Counter
for i in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	x = 0
	ans = 0
	ptr = 0
	mod = sorted(list(Counter([k - i % k for i in arr if i % k > 0]).items()))
	mod = [[i[0], i[1]] for i in mod]
	num = 0
	n_req = sum([i[1] for i in mod])
	while mod and num < n_req:
		avail = x % k
		if mod[ptr][1] > 0:
			if mod[ptr][0] >= avail:
				ans += mod[ptr][0] - avail + 1
				x += mod[ptr][0] - avail + 1
			else:
				ans += k - avail
				x += k - avail
				ans += mod[ptr][0] + 1
				x += mod[ptr][0] + 1
			mod[ptr][1] -= 1
			num += 1
			ptr += 1
			ptr %= len(mod)
		else:
			ptr += 1
			ptr %= len(mod)
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = {}
	for i in range(n):
		q = k - a[i] % k
		if q in b:
			b[q] += 1
		else:
			b[q] = 1
	ans = 0
	for i in b:
		if i != k:
			ans = max(ans, i + b[i] * k - k)
	print(ans + (ans != 0))


from collections import Counter as Cnt
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [k - int(x) % k for x in input().split() if int(x) % k != 0]
	if not a:
		print(0)
	else:
		c = Cnt(a)
		h_c = sorted(c.most_common(), key=lambda x: (-x[1], -x[0]))[0]
		print(h_c[0] + 1 + k * (h_c[1] - 1))


from collections import defaultdict
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	freq = defaultdict(int)
	rem = [0] * n
	for i in range(n):
		rem[i] = a[i] % k
		freq[rem[i]] += 1
	mx = 0
	for (key, v) in freq.items():
		if key != 0:
			mx = max(mx, k - key + k * (v - 1))
	if mx == 0:
		print(0)
	else:
		print(mx + 1)


production = True
import sys, math, collections

def input(input_format=0, multi=0):
	if multi > 0:
		return [input(input_format) for i in range(multi)]
	else:
		next_line = sys.stdin.readline()[:-1]
		if input_format >= 10:
			use_list = False
			input_format = int(str(input_format)[-1])
		else:
			use_list = True
		if input_format == 0:
			formatted_input = [next_line]
		elif input_format == 1:
			formatted_input = list(map(int, next_line.split()))
		elif input_format == 2:
			formatted_input = list(map(float, next_line.split()))
		elif input_format == 3:
			formatted_input = list(next_line)
		elif input_format == 4:
			formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
		elif input_format == 5:
			formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
		elif input_format == 6:
			formatted_input = next_line.split()
		else:
			formatted_input = [next_line]
		return formatted_input if use_list else formatted_input[0]

def out(output_line, output_format=0, newline=True):
	formatted_output = ''
	if output_format == 0:
		formatted_output = str(output_line)
	elif output_format == 1:
		formatted_output = ' '.join(map(str, output_line))
	elif output_format == 2:
		formatted_output = '\n'.join(map(str, output_line))
	print(formatted_output, end='\n' if newline else '')

def log(*args):
	if not production:
		print('$$$', end='')
		print(*args)
enum = enumerate

def solve():
	(n, k) = input(1)
	a = input(1)
	r = [k - i % k for i in a]
	r.sort()
	log(a)
	log(r)
	b = dict()
	for i in r:
		b.setdefault(i, 0)
	for i in r:
		if i == k:
			continue
		else:
			o = i + b[i] * k
			b[i] += 1
	log(b)
	m = 0
	a = k
	d = True
	for i in r[::-1]:
		if b[i]:
			d = False
		if b[i] > m:
			m = b[i]
			a = i
	log(m, k, a, d)
	if d:
		out(0)
		return
	out(m * k - (k - a - 1))
	return
for i in range(input(11)):
	solve()


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


t = int(input())
while t:
	line = input().split()
	(n, k) = (int(line[0]), int(line[1]))
	a = input().split()
	a = list(map(int, a))
	d = {}
	for i in range(n):
		a[i] = (k - a[i] % k) % k
		if a[i] != 0:
			if a[i] not in d:
				d[a[i]] = 0
			d[a[i]] += 1
	if len(d):
		d = list(d.items())
		d.sort(key=lambda x: x[1])
		ans = (d[-1][1] - 1) * k
		mi = -1
		for i in range(len(d)):
			if d[i][1] == d[-1][1]:
				if mi == -1 or d[i][0] > d[mi][0]:
					mi = i
		ans += d[mi][0] + 1
		print(ans)
	else:
		print(0)
	t -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = {a[i] % k: 0 for i in range(n)}
	for i in a:
		if i % k == 0:
			continue
		s[i % k] += 1
	x = 0
	for i in s.keys():
		x = max(x, s[i] * k - i)
	print(x + 1 if x != 0 else 0)


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	d = {}
	for num in arr:
		d[num % k] = d.get(num % k, 0) + 1
	ans = 0
	for key in d.keys():
		if key != 0:
			freq = d[key]
			tempAns = freq * k - key
			ans = max(ans, tempAns)
	print(ans + 1 if ans != 0 else ans)
	t -= 1


r = lambda : map(int, input().split())
(t,) = r()
for _ in [0] * t:
	(n, k) = r()
	a = [*r()]
	s = {i % k: 0 for i in a}
	for i in a:
		if i % k:
			s[i % k] += 1
	f = max((1 - i + k * s[i] for i in s.keys()))
	print(f if f > 1 else 0)


from collections import defaultdict
from operator import itemgetter

def max_occurrences(seq):
	c = defaultdict(int)
	for item in seq:
		c[item] += 1
	return max(c.items(), key=itemgetter(1))
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a = [i for i in a if i % k != 0]
	b = [abs(i % k - k) for i in a]
	b = sorted(b, reverse=True)
	if b:
		(num, occ) = (max_occurrences(b)[0], max_occurrences(b)[1])
		ans = k * (occ - 1) + num + 1
		print(ans)
	else:
		print(0)


from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	d = Counter()
	for i in arr:
		if i % k != 0:
			d[k - i % k] += 1
	ma = 0
	for i in d:
		ma = max(ma, i + d[i] * k - k + 1)
	print(ma)


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	d = dict()
	d[0] = 0
	for v in l:
		vv = (k - v) % k
		if vv:
			if vv not in d:
				d[vv] = vv + 1
			else:
				d[vv] += k
	print(max(d.values()))


t = int(input())
while t > 0:
	t -= 1
	(n, k) = map(int, input().split())
	li = list(map(int, input().split()))
	m = {}
	for i in li:
		if i % k == 0:
			if i % k in m:
				m[i % k] += 1
			else:
				m[i % k] = 0
		else:
			x = k - i % k
			if x in m:
				m[x] += 1
			else:
				m[x] = 0
	ma = 0
	for (key, val) in m.items():
		if key != 0:
			x = key + val * k
			ma = max(ma, x)
	if ma != 0:
		ma += 1
	print(ma)


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	z = []
	for i in l:
		if i % k != 0:
			z.append(k - i % k)
	count = 0
	z.sort(reverse=True)
	prev = 0
	a = 0
	for i in range(len(z)):
		if z[i] == prev:
			z[i] += a * k
			a += 1
		else:
			prev = z[i]
			a = 1
	z.sort(reverse=True)
	x = 0
	stack = deque()
	while z or stack:
		if len(z) > 0:
			t = z.pop()
			if len(stack) > 0 and stack[-1] <= t:
				z.append(t)
				t = stack.pop()
		else:
			t = stack.pop()
		if t > x:
			count += t - x + 1
			x = t + 1
		elif t == x:
			count += 1
			x += 1
		else:
			stack.appendleft(t + k)
	print(count)


test = int(input())
for _ in range(test):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	hashset = {}
	for i in range(n):
		if arr[i] % k:
			v = k - arr[i] % k
			hashset[v] = hashset.get(v, 0) + 1
	maxi = 0
	for (key, v) in hashset.items():
		maxi = max(maxi, key)
		if v > 1:
			val = (v - 1) * k + key
			maxi = max(maxi, val)
	if maxi == 0:
		print(0)
	else:
		print(maxi + 1)


inp = lambda : map(int, input().split(' '))
(t,) = inp()
for _ in range(t):
	(n, k) = inp()
	arr = list(inp())
	count = {}
	max_val = 0
	max_index = 0
	for i in arr:
		rem = (k - i % k) % k
		if rem not in count:
			count[rem] = 0
		count[rem] += 1
		if count[rem] > max_val and rem != 0:
			max_val = count[rem]
			max_index = rem
		elif count[rem] == max_val and rem > max_index:
			max_val = count[rem]
			max_index = rem
	if max_val == 0:
		print(0)
	else:
		print((max_val - 1) * k + max_index + 1)


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(i) % k for i in input().split()]
	t = dict()
	for i in a:
		if i != 0:
			try:
				t[k - i] += 1
			except KeyError:
				t[k - i] = 1
	if len(t) == 0:
		print(0)
		continue
	(maxx, val) = (0, 0)
	for i in t.keys():
		if t[i] > maxx:
			maxx = t[i]
			val = i
		elif t[i] == maxx and i > val:
			val = i
			maxx = t[i]
	print((maxx - 1) * k + 1 + val)


def Solve():
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	a = input().split()
	a = [int(x) for x in a]
	dic = {}
	c = 0
	for i in range(len(a)):
		x = (k - a[i] % k) % k
		if x:
			if dic.get(x) != None:
				c = max(c, k * dic[x] + x + 1)
				dic[x] += 1
			else:
				c = max(c, k * 0 + x + 1)
				dic[x] = 1
	print(c)
q = int(input())
while q:
	Solve()
	q -= 1


import sys
import math
from math import *
from collections import defaultdict
import os
from io import BytesIO, IOBase
from collections import deque

def check(d):
	if list(d.keys()) == ['a', 'b', 'c']:
		if d['a'] == d['c'] or d['b'] == d['c']:
			return True
	return False

def main(d):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	d = defaultdict(lambda : 0)
	for i in a:
		if i % k == 0:
			continue
		d[k - i % k] += 1
	c = 0
	x = -1
	mx = 0
	midx = 0
	if len(d.keys()) == 0:
		print(0)
		return
	for (i, j) in d.items():
		if j >= mx:
			mx = j
	for j in reversed(sorted(list(d.keys()))):
		if d[j] == mx:
			midx = j
			break
	print(k * (mx - 1) + midx + 1)
d = defaultdict(lambda : 0)
for i in range(int(input())):
	main(d)


def Foo():
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	b = [0] * len(a)
	for i in range(len(a)):
		rem = a[i] % k
		b[i] = k - rem if rem != 0 else rem
	b.sort()
	startI = 0
	for i in range(len(b)):
		if b[i] != 0:
			startI = i
			break
	else:
		print(0)
		return
	flag = False
	blockStartI = -1
	blockLen = 0
	for i in range(startI, len(b)):
		if i != len(b) - 1 and b[i] == b[i + 1]:
			if blockStartI == -1:
				blockStartI = i
			blockLen += 1
			flag = True
		else:
			if blockStartI != -1:
				blockLen += 1
			for j in range(1, blockLen):
				b[blockStartI + j] += k * j
			blockStartI = -1
			blockLen = 0
	b.sort()
	print(b[len(b) - 1] + 1)

def main():
	t = int(input())
	for i in range(t):
		Foo()
main()


t = int(input())
for test in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = [0] * n
	for i in range(n):
		b[i] = (k - a[i] % k) % k
	b.sort()
	result = 0
	minresult = 0
	mc = 0
	mmc = 0
	c = 0
	tek = 0
	s = False
	s1 = True
	for i in range(n):
		if b[i] == 0:
			continue
		if tek == b[i]:
			c += 1
			if c == mc:
				if b[i] > mmc:
					mmc = b[i]
			if c > mc:
				mc = c
				minresult += k
				mmc = b[i]
			s = True
		else:
			s = False
			c = 0
		if s1:
			s1 = False
			result = 1
		result += b[i] - tek
		tek = b[i]
	minresult += mmc
	if minresult != 0:
		minresult += 1
	print(max(minresult, result))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(lambda x: (k - int(x) % k) % k, input().split()))
	occ = {}
	mx = 0
	mx_v = 0
	for e in a:
		if e != 0:
			val = occ.setdefault(e, 0) + 1
			if val > mx or (val >= mx and e > mx_v):
				mx = val
				mx_v = e
			occ[e] = val
	res = mx_v + (mx - 1) * k + 1 if mx > 0 else 0
	print(res)


def cast(cre, typ):
	return type(typ)(map(cre, typ))

def input_ilst():
	return cast(int, input().split())

def input_slst():
	return input().split()

def solution():
	for t in range(int(input())):
		(n, k) = input_ilst()
		lst = input_ilst()
		dic = {}
		ans = 0
		for e in lst:
			if e % k != 0:
				if dic.get(e % k) != None:
					dic[e % k] += 1
				else:
					dic[e % k] = 1
		lst = sorted(dic.items())
		if len(lst) != 0:
			mfe = max(lst, key=lambda x: x[1])[0]
			amfe = dic[mfe]
			ans = k * (amfe - 1) + (k - mfe) + 1
		print(ans)
	return
solution()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	li = list(map(int, input().split()))
	dic = {}
	for ele in li:
		dic[ele % k] = dic.get(ele % k, 0) + 1
	if 0 in dic:
		if dic[0] == n:
			print(0)
			continue
	dic[0] = 0
	(maxi, ke) = (max(dic.values()), k)
	for (key, v) in dic.items():
		if maxi == v:
			ke = min(key, ke)
	print(k * (maxi - 1) + (k - ke + 1))


from collections import deque
import sys

def inp():
	return sys.stdin.readline().strip()
for _ in range(int(inp())):
	(n, k) = map(int, inp().split())
	a = list(map(int, inp().split()))
	d = {}
	f = 0
	mx = -1
	for i in a:
		if i % k == 0:
			continue
		if i % k not in d:
			d[i % k] = 0
		d[i % k] += 1
		if f < d[i % k]:
			f = d[i % k]
			mx = i % k
		elif f == d[i % k]:
			mx = min(mx, i % k)
	if mx == -1:
		print(0)
		continue
	print((f - 1) * k + (k - mx) + 1)


from collections import defaultdict
for _ in range(int(input())):
	(i_liczb, dzielnik) = map(int, input().split())
	ile_brak = defaultdict(int)
	for x in input().split():
		x = int(x)
		cos = dzielnik - x % dzielnik
		if cos == dzielnik:
			continue
		ile_brak[cos] += 1
	if ile_brak != {}:
		maks = 0
		maks_war = 0
		for (x, y) in ile_brak.items():
			if y > maks_war:
				maks = x
				maks_war = y
			elif y == maks_war and x > maks:
				maks = x
		print(maks + 1 + (maks_war - 1) * dzielnik)
	else:
		print(0)


from collections import defaultdict as dft

def mp():
	return map(int, input().split())

def ml():
	return list(map(int, input().split()))
for _ in range(int(input())):
	(n, k) = mp()
	arr = ml()
	dct = dft(int)
	mx = 0
	ans = 0
	for i in range(n):
		t = arr[i] % k
		if t == 0:
			continue
		dct[k - t] += 1
		mx = max(mx, dct[k - t])
	for (key, val) in dct.items():
		if val == mx:
			ans = max(ans, k * (val - 1) + key + 1)
	print(ans)


import collections

def main():
	(n, k) = map(int, input().split(' '))
	a = [k - int(x) % k for x in input().split(' ') if int(x) % k > 0]
	if len(a) == 0:
		return 0
	a.sort()
	c = collections.Counter(a)
	top = c.most_common()
	(v, m) = top[0]
	for z in top:
		if z[1] != m:
			break
		v = max(v, z[0])
	return k * (m - 1) + v + 1
for _ in range(int(input())):
	print(main())


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	new = [0] * n
	arr.sort()
	new = dict()
	for i in range(n):
		new.setdefault(k - arr[i] % k if arr[i] % k != 0 else 0, 0)
		new[k - arr[i] % k if arr[i] % k != 0 else 0] += 1
	ans = 0
	for (key, el) in new.items():
		if not key:
			continue
		if el == 1:
			ans = max(ans, key + 1)
		else:
			ans = max(ans, key + k * (el - 1) + 1)
	print(ans)


t = int(input())
while t != 0:
	t -= 1
	(n, k) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	chk = 0
	done = {}
	ans = 0
	arr.sort()
	for i in range(len(arr)):
		if arr[i] % k == 0:
			continue
		need = k - arr[i] % k
		if need not in done:
			done[need] = 0
		ans = max(done[need] * k + need, ans)
		done[need] += 1
	if ans != 0:
		print(ans + 1)
	else:
		print(0)


for _ in range(int(input())):
	(X, Y) = map(int, input().split())
	arr = list(map(int, input().split()))
	dict = {}
	flag = True
	for i in arr:
		if i % Y != 0:
			flag = False
			break
	if flag:
		print(0)
		continue
	for i in arr:
		if i % Y == 0:
			continue
		if i > Y:
			difference = Y - i % Y
			if difference != 0:
				if difference not in dict:
					dict[difference] = 0
				dict[difference] += 1
		else:
			difference = Y - i
			if difference != 0:
				if difference not in dict:
					dict[difference] = 0
				dict[difference] += 1
	res = []
	for i in dict:
		cnts = dict[i]
		initial = i
		while cnts > 0:
			res.append(initial)
			initial += Y
			cnts -= 1
	print(max(res) + 1)


for case in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	series = [int(x) for x in input().split()]
	new_series = []
	for i in range(n):
		if series[i] % k == 0:
			series[i] = 0
		else:
			series[i] = k - series[i] % k
			new_series.append(series[i])
	new_series.sort()
	n = len(new_series)
	if n == 0:
		print(0)
		continue
	i = 0
	while i < n:
		j = i
		while j + 1 < n and new_series[j + 1] == new_series[i]:
			new_series[j + 1] = new_series[i] + k * (j + 1 - i)
			j += 1
		i = j + 1
	print(max(new_series) + 1)


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
dgnl = lambda x: sqrt(2 * x ** 2)
for _ in range(I()):
	(n, k) = R()
	a = sorted([k - i % k for i in R() if i % k])
	if not a or a[-1] == 0:
		print(0)
		continue
	p = 1
	b = -1
	for i in a:
		if i >= p:
			p = i + 1
			b = i
			cur = i + 1
		elif i == b:
			cur += k
			if cur > p:
				p = cur
		else:
			b = i
			cur = i + 1
	print(p)


t = int(input())

def num_changes(numbers, divisor):
	for i in range(len(numbers)):
		numbers[i] = divisor - numbers[i] % divisor
	numbers.sort()
	to_add = [[numbers[0], 0]]
	for elem in numbers:
		if to_add[-1][0] == elem:
			to_add[-1][1] += 1
		else:
			to_add.append([elem, 1])
	num_oper = []
	for pair in to_add:
		if pair[0] != divisor:
			num_oper.append(pair[0] + (pair[1] - 1) * divisor)
	if not num_oper:
		return 0
	else:
		return max(num_oper) + 1
for i in range(t):
	(n, divisor) = map(int, input().split())
	numbers = list(map(int, input().split()))
	print(num_changes(numbers, divisor))


import collections
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	x = 0
	D = [k - a[i] % k for i in range(n) if a[i] % k]
	D.sort(reverse=True)
	ans = 0
	if len(D):
		C = collections.Counter(D).most_common()
		ans = (C[0][1] - 1) * k + C[0][0] + 1
	print(ans)


from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
import itertools as it
from math import sqrt, log, log2
from fractions import Fraction
import random
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	nums = list(map(int, stdin.readline().split()))
	freq = dd(int)
	(maxkey, maxval) = (-1, 0)
	for i in nums:
		t = i % k
		if t != 0:
			freq[k - t] += 1
			if freq[k - t] > maxval:
				maxval = freq[k - t]
	maxkey = 0
	for key in freq:
		if freq[key] == maxval and key > maxkey:
			maxkey = key
	if len(freq) == 0:
		print(0)
		continue
	nummoves = (maxval - 1) * k + (maxkey + 1)
	print(nummoves)


from collections import *
R = lambda : map(int, input().split())
(t,) = R()
for _ in [0] * t:
	(n, k) = R()
	c = Counter((1 - x % k for x in R()))
	del c[1]
	print(max(0, 0, *(x + k * c[x] for x in c)))


import sys
input = sys.stdin.readline
from collections import Counter
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [(k - int(item)) % k for item in input().split()]
	cnt = Counter(a)
	ans = 0
	for (key, val) in cnt.items():
		if key == 0:
			continue
		ans = max(ans, key + (val - 1) * k)
	if ans == 0:
		print(0)
	else:
		print(ans + 1)


import collections

def solve(arr, k):
	arr = [k - v % k for v in arr if v % k != 0]
	if len(arr) == 0:
		return 0
	counter = collections.Counter(arr)
	max_cnt_key = arr[0]
	for key in sorted(counter):
		if counter[key] >= counter[max_cnt_key]:
			max_cnt_key = key
	return (counter[max_cnt_key] - 1) * k + max_cnt_key + 1
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(*arr,) = map(int, input().split())
	print(solve(arr, k))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	max_freq = 0
	freqElement = -1
	for i in a:
		if i % k:
			m = i % k
			m = k - m
			if m not in d:
				d[m] = 1
				if 1 > max_freq:
					max_freq = 1
					freqElement = m
				elif 1 == max_freq:
					if freqElement < m:
						freqElement = m
			else:
				d[m] += 1
				if d[m] > max_freq:
					max_freq = d[m]
					freqElement = m
				elif d[m] == max_freq:
					if freqElement < m:
						freqElement = m
	if freqElement != -1:
		print(k * (max_freq - 1) + freqElement + 1)
	else:
		print(0)


def solve():
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = {}
	for e in l:
		if e % k != 0:
			if e % k in d:
				d[e % k] += 1
			else:
				d[e % k] = 1
	vals = d.values()
	if len(vals) == 0:
		return 0
	Max = max(vals)
	Min = k
	for (key, val) in d.items():
		if val == Max and key < Min:
			Min = key
	return (Max - 1) * k + (k - Min + 1)
t = int(input())
for i in range(t):
	ans = solve()
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l1 = [0] * n
	for i in range(n):
		if l[i] % k != 0:
			o = l[i] // k + 1
			l1[i] = o * k - l[i]
	l1.sort()
	s = l1[0]
	p = 0
	for i in range(1, n):
		if l1[i] > 0:
			if l1[i] > l1[i - 1]:
				s = l1[i]
			else:
				s = k + s
		p = max(p, s)
	if p == 0:
		if len(l1) == 1 and l1[0] != 0:
			print(l1[0] + 1)
		else:
			print(0)
	else:
		print(p + 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	s = {}
	for i in l:
		if i % k == 0:
			continue
		if k - i % k not in s:
			s[k - i % k] = 1
		else:
			s[k - i % k] += 1
	x = 0
	for (i, j) in s.items():
		x = max(x, i + (j - 1) * k + 1)
	print(x)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	if k == 1:
		print(0)
		continue
	D = dict()
	for i in range(n):
		toAdd = (k - A[i] % k) % k
		if toAdd > 0:
			D[toAdd] = D.get(toAdd, 0) + 1
	if len(D) == 0:
		print(0)
		continue
	maxCount = 0
	for v in D.values():
		maxCount = max(maxCount, v)
	maxValue = 0
	for key in D.keys():
		if D[key] == maxCount:
			maxValue = max(maxValue, key)
	print((maxCount - 1) * k + 1 + maxValue)


from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l = []
	for i in range(len(l1)):
		l1[i] = k - l1[i] % k
		if l1[i] % k != 0:
			l.append(l1[i])
	c = dict(Counter(l))
	maxx = 0
	d = dict()
	for (x, y) in c.items():
		if y in d:
			d[y].append(x)
		else:
			d[y] = [x]
	for (x, y) in d.items():
		d[x] = sorted(d[x], reverse=True)
	val = sorted(d.keys(), reverse=True)
	if len(d) == 0:
		print(0)
	else:
		print(val[0] * k - (k - d[val[0]][0]) + 1)


import math
import sys
import collections
import bisect
from collections import defaultdict
from sys import stdin, stdout
MOD = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 7)

def take_root(num):
	return math.ceil(math.sqrt(num))

def sieve():
	limit = 86028121
	isprime = [1] * 86028122
	isprime[0] = 0
	isprime[1] = 0
	for i in range(2, take_root(limit + 1)):
		if isprime[i] == 1:
			for j in range(i * i, limit + 1, i):
				isprime[j] = 0
	primes = []
	for i in range(limit + 1):
		if isprime[i] == True:
			primes.append(i)
	return primes

def minput():
	return map(int, input().split())

def iinput():
	return int(input())

def strinput():
	return input()

def linput():
	return list(map(int, input().split()))
for _ in range(iinput()):
	(n, x) = minput()
	arr = linput()
	mod_ar = []
	for i in range(n):
		if arr[i] % x != 0:
			mod_ar.append(x - arr[i] % x)
	if len(mod_ar) == 0:
		print(0)
		continue
	d1 = defaultdict(int)
	for i in mod_ar:
		d1[i] += 1
	(max1, key) = (-1, -1)
	for i in sorted(d1.keys()):
		if d1[i] >= max1:
			max1 = d1[i]
			key = max(key, i)
	ans = (max1 - 1) * x + key + 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted([(k - int(i) % k) % k for i in input().split()])
	b = a.copy()
	for i in range(1, n):
		if a[i] != 0 and a[i] == a[i - 1]:
			b[i] = b[i - 1] + k
	ans = max(b)
	if ans == 0:
		print(0)
	else:
		print(ans + 1)


def checker(n, k, lst):
	d = {}
	for i in range(n):
		f = lst[i]
		if f % k != 0:
			if k - f % k in d:
				d[k - f % k] += 1
			else:
				d[k - f % k] = 1
	(ans, tmp) = (0, 0)
	for i in d:
		if d[i] > ans:
			(ans, tmp) = (d[i], i)
		elif d[i] == ans:
			if i > tmp:
				tmp = i
	if ans > 0:
		ans = (ans - 1) * k + tmp + 1
	return ans
for _ in range(int(input())):
	(N, K) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	print(checker(N, K, a))


from sys import stdin, stdout
LI = lambda : list(map(int, input().split()))
MAP = lambda : map(int, input().split())
IN = lambda : int(input())
S = lambda : input()
import math
from collections import Counter, defaultdict
for _ in range(IN()):
	(n, k) = MAP()
	a = LI()
	ans = 0
	d = defaultdict(int)
	for i in range(n):
		if a[i] % k == 0:
			continue
		x = k - a[i] % k
		d[x] += 1
	if not d:
		print(0)
		continue
	for i in d:
		ans = max(ans, i + (d[i] - 1) * k)
	print(ans + 1)


def solve():
	(n, k) = map(int, input().split(' '))
	l = list(map(int, input().split(' ')))
	dic = {}
	for e in l:
		if e % k == 0:
			continue
		key = k - e % k
		if key in dic.keys():
			dic[key] += 1
		else:
			dic[key] = 1
	ele = list(dic.keys())
	if len(ele) == 0:
		print(0)
		return
	Mkey = ele[0]
	Mval = dic[ele[0]]
	for e in ele:
		if dic[e] > Mval:
			Mval = dic[e]
			Mkey = e
	res = 0
	for e in ele:
		if dic[e] == Mval:
			res = max(res, k * (dic[e] - 1) + e + 1)
	print(res)
t = int(input())
while t:
	solve()
	t -= 1


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	temp = 0
	used = {}
	ans = 0
	for i in range(n):
		if a[i] % k != 0:
			a[i] = k - a[i] % k
			if a[i] not in used:
				used[a[i]] = 0
			(used[a[i]], a[i]) = (used[a[i]] + 1, a[i] + k * used[a[i]])
			if a[i] > ans:
				ans = a[i]
	if len(used) == 0:
		print(0)
	else:
		print(ans + 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = {}
	d[0] = 0
	if k == 1:
		print(0)
		continue
	for i in range(n):
		temp = l[i] % k
		if temp == 0:
			d[0] += 1
		elif k - temp in d:
			d[k - temp] += 1
		else:
			d[k - temp] = 1
	del d[0]
	m = 0
	index = 0
	for i in d:
		if d[i] == m and i > index:
			index = i
		if d[i] > m:
			m = d[i]
			index = i
	val = 0
	if m == 0:
		print(0)
		continue
	print((m - 1) * k + (index + 1))


from collections import defaultdict
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	rem = [0] * n
	mp = defaultdict(int)
	_max = -1
	idx = 0
	for i in range(n):
		if a[i] % k == 0:
			rem[i] = 0
			continue
		else:
			rem[i] = k - a[i] % k
		mp[rem[i]] += 1
		if mp[rem[i]] > _max:
			idx = i
			_max = mp[rem[i]]
		elif mp[rem[i]] == _max and rem[i] > rem[idx]:
			idx = i
	if _max == -1:
		print(0)
	else:
		print((_max - 1) * k + rem[idx] + 1)


INT_MAX = 10 ** 30 + 7
MOD = 10 ** 9 + 7

def INPUT():
	return list((int(i) for i in input().split()))

def LIST_1D_ARRAY(n):
	return [0 for _ in range(n)]

def LIST_2D_ARRAY(m, n):
	return [[0 for _ in range(n)] for _ in range(m)]
for i in range(int(input())):
	(n, k) = INPUT()
	A = INPUT()
	mod = [0] * n
	for i in range(n):
		mod[i] = A[i] % k
	D = {}
	mod.sort()
	for i in range(n):
		if mod[i] in D:
			D[mod[i]] += 1
		else:
			D[mod[i]] = 1
	if mod[0] == 0 and mod[-1] == 0:
		print(0)
	else:
		ans = 0
		for ele in D:
			if ele != 0:
				ans = max(ans, k - ele + k * (D[ele] - 1) + 1)
		print(ans)


t = int(input())
while t:
	t -= 1
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	d = {}
	for i in range(len(arr)):
		if arr[i] % k == 0:
			continue
		diff = (k - arr[i]) % k
		if diff in d.keys():
			d[diff][1] += 1
			if arr[i] > d[diff][0]:
				d[diff][0] = arr[i]
		else:
			d[diff] = [arr[i], 1]
	sorted_by_value = sorted(d.items(), key=lambda x: (-x[1][1], -x[0]))
	ans = 0
	if sorted_by_value:
		ans += k * (sorted_by_value[0][1][1] - 1) + sorted_by_value[0][0] + 1
	print(ans)


def solve():
	(n, k) = list(map(int, input().split()))
	count = {}
	a = list(map(int, input().split()))
	for i in range(0, n):
		addition = k - a[i] % k
		if addition == k:
			continue
		if addition not in count:
			count[addition] = 1
		elif a[i] % k != 0:
			count[addition] += 1
	max = 0
	for (key, value) in count.items():
		curr_addition = key + k * (value - 1)
		max = curr_addition if curr_addition > max else max
	max = 0 if max == 0 else max + 1
	print(max)
t = int(input())
for i in range(0, t):
	solve()


def minsteps(nums, k):
	hashmap = dict()
	steps = 0
	for num in nums:
		if num % k == 0:
			continue
		target = k - num if k > num else k * (num // k + 1) - num
		if target in hashmap:
			steps = max(steps, hashmap[target] + k)
			hashmap[target] += k
		else:
			steps = max(steps, target)
			hashmap[target] = target
	return steps + 1 if steps else 0
t = int(input())
for _ in range(t):
	(_, k) = list(map(int, input().split()))
	nums = list(map(int, input().split()))
	print(minsteps(nums, k))


import os
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())
test_count = int(input())
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	(n, k) = invr()
	a = inlt()
	cnt = {}
	done = 0
	for i in range(n):
		r = k - a[i] % k
		if r != k:
			cnt[r] = cnt.get(r, 0) + 1
		else:
			done += 1
	if done == n:
		print(0)
	else:
		last = 0
		ans = 0
		while done != n:
			removed = []
			for el in sorted(cnt.keys()):
				if last == el:
					cnt[el] -= 1
					last += 1
					ans += 1
					done += 1
				else:
					if last < el:
						ans += el - last
					else:
						ans += k + el - last
					last = el
					cnt[el] -= 1
					last += 1
					ans += 1
					done += 1
				if cnt[el] == 0:
					removed.append(el)
				if done == n:
					break
				last = last % k
			for x in removed:
				del cnt[x]
		print(ans)


import sys
import math

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	(n, k) = MI()
	a = sorted(LI())
	l = [k - x % k for x in a if x % k != 0]
	d = {}
	m = 0
	for i in l:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
		if d[i] > m:
			m = d[i]
	temp = 0
	for i in l:
		if d[i] == m and i > temp:
			temp = i
	if temp == 0:
		print(0)
	else:
		print(temp + k * (d[temp] - 1) + 1)


import sys
import math
import operator as op
from functools import reduce
from bisect import *
from collections import OrderedDict
from collections import deque
import heapq

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def read_float_line():
	return [float(v) for v in sys.stdin.readline().split()]

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer / denom

def index(a, x):
	i = bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	return -1

def find_lt(a, x):
	i = bisect_left(a, x)
	if i:
		return i - 1
	return -1

def find_le(a, x):
	i = bisect_right(a, x)
	if i:
		return i - 1
	return -1

def find_gt(a, x):
	i = bisect_right(a, x)
	if i != len(a):
		return i
	return -1

def find_ge(a, x):
	i = bisect_left(a, x)
	if i != len(a):
		return i
	return -1
mod = int(1000000000.0) + 7
mod2 = 998244353
t = read_int()
for i in range(t):
	(n, k) = read_int_line()
	a = read_int_line()
	for i in range(n):
		a[i] = a[i] % k
		a[i] = (k - a[i]) % k
	a.sort()
	i = 0
	while i < n and a[i] == 0:
		i += 1
	if i == n:
		print(0)
		continue
	x = 0
	ans = 0
	d = {}
	for i in a:
		if i != 0:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	l = []
	for i in d:
		for j in range(d[i]):
			l.append(j * k + i)
	l.sort()
	for i in l:
		if i == x:
			ans += 1
			x += 1
		else:
			ans += i - x + 1
			x = i + 1
	print(ans)


def main():
	(n, k) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	f = []
	for j in range(0, n):
		f.append(l[j] % k)
	f.sort()
	d = {}
	for j in f:
		d[j] = 0
	for j in f:
		d[j] += 1
	m = 0
	c1 = 0
	for j in range(0, len(f)):
		if d[f[j]] > m and f[j] != 0:
			m = d[f[j]]
			c1 = f[j]
	if c1 == 0:
		print(0)
		return
	j = 0
	c = 0
	while j < m:
		c += k
		j += 1
	print(c - c1 + 1)
t = int(input())
for i in range(0, t):
	main()


from collections import defaultdict
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(map(int, input().split()))
	d = defaultdict(int)
	e = dict()
	for i in a:
		if i % k and k - i % k:
			d[k - i % k] += 1
			e[k - i % k] = i
	t = sorted(d)
	ans = 0
	for i in t:
		ans = max((d[i] - 1) * k + i, ans)
	if ans:
		print(ans + 1)
	else:
		print(0)


_MULTITEST = True

def solve():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	r = [(k - x % k) % k for x in a]
	r.sort()
	increment = [0] * n
	for i in range(1, n):
		if r[i] == 0:
			continue
		if r[i - 1] == r[i]:
			increment[i] = increment[i - 1] + k
	for i in range(n):
		r[i] += increment[i]
	r.sort()
	op = 0
	x = 0
	for i in range(n):
		if r[i] != 0:
			if x < r[i]:
				op += r[i] - x
				x = r[i]
			op += 1
			x += 1
	print(op)
t = int(input()) if _MULTITEST else 1
for tt in range(t):
	solve()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	d = {}
	for x in arr:
		if x % k:
			d[k - x % k] = d.get(k - x % k, 0) + 1
	try:
		mx = max(d.values())
	except ValueError:
		mx = 0
	ans = 0
	mx_key = -1
	for (key, value) in d.items():
		if value == mx and key > mx_key:
			ans = (mx - 1) * k + key + 1
			mx_key = key
	print(ans)


from decimal import *
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split(' '))
	l = list(map(int, input().split(' ')))
	for i in range(n):
		if l[i] % k == 0:
			l[i] = 0
		else:
			l[i] = k - l[i] % k
	l = sorted(l)
	ans = Decimal(0)
	count = 1
	for i in range(1, n):
		if l[i] == l[i - 1] and l[i] != 0:
			ans = Decimal(max(ans, Decimal(l[i] + Decimal(count) * Decimal(k))))
			count += 1
		else:
			ans = Decimal(max(ans, l[i]))
			count = 1
	if n == 1:
		if l[0] == 0:
			print(0)
		else:
			print(l[0] + 1)
	elif ans == 0:
		print(0)
	else:
		print(ans + Decimal(1))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	(lst, arr) = ([], [])
	lst = list(map(int, input().split()))
	for i in range(n):
		if lst[i] % k != 0:
			arr += [k - lst[i] % k]
		else:
			arr += [0]
	d = {}
	for i in range(n):
		if arr[i] not in d.keys():
			d[arr[i]] = 1
		else:
			d[arr[i]] += 1
	(cnt, a, c) = (0, 0, 0)
	for i in d:
		if (d[i] - 1) * k + i > cnt and i != 0:
			cnt = (d[i] - 1) * k + i
		a += 1
	if 0 in d.keys() and d[0] == n:
		print(0)
	else:
		print(cnt + 1)


from collections import defaultdict
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = defaultdict(lambda : 0)
	maxVal = 0
	for i in range(n):
		if l[i] % k != 0:
			l[i] = k - l[i] % k
		else:
			l[i] = 0
			continue
		d[l[i]] += 1
		l[i] += k * (d[l[i]] - 1)
		if l[i] > maxVal:
			maxVal = l[i]
	print(maxVal + 1 if maxVal > 0 else 0)


for T in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	d = {}
	for i in a:
		d[(k - i % k) % k] = d.get((k - i % k) % k, 0) + 1
	ma = 0
	if d.get(0, 0) == n:
		print(0)
	else:
		for i in d:
			if i > 0:
				ma = max(ma, k * (d[i] - 1) + i + 1)
		print(ma)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	o = []
	for i in a:
		if i % k != 0:
			o.append(k - i % k)
	if len(o) == 0:
		print(0)
		continue
	o.sort()
	i = 0
	j = 0
	mv = o[0]
	mt = 0
	while j < len(o):
		if o[j] != o[i]:
			if mt <= j - i:
				mv = o[i]
				mt = j - i
			i = j
			j += 1
		else:
			j += 1
	if mt <= j - i:
		mv = o[i]
		mt = j - i
	print((mt - 1) * k + 1 + mv)


t = int(input())

def function(s, k):
	return (k - s % k) * (s % k != 0)
answer = []
for _ in range(t):
	(n, k) = map(int, input().split(' '))
	a = [function(x, k) for x in list(map(int, input().split(' ')))]
	a.sort()
	max_count = 0
	remainder = 0
	actual = 0
	count_actual = 0
	for i in range(n):
		if actual != a[i]:
			if count_actual >= max_count or remainder == 0:
				max_count = count_actual
				remainder = actual
			actual = a[i]
			count_actual = 1
		else:
			count_actual += 1
	if count_actual >= max_count or remainder == 0:
		max_count = count_actual
		remainder = actual
	tmp = (k * (max_count - 1) + remainder + 1) * (remainder != 0)
	answer.append(str(tmp))
print('\n'.join(answer))


from collections import defaultdict

def func(arr, n):
	d = defaultdict(int)
	for i in arr:
		temp = i % n
		if temp != 0:
			d[n - temp] += 1
	if len(d) == 0:
		return 0
	maxm = max(d.values())
	value = 0
	for (i, j) in d.items():
		if j == maxm and i > value:
			value = i
	return n * (maxm - 1) + value + 1
t = int(input())
for _ in range(t):
	(a, n) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(func(arr, n))


from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = list(map(lambda x: k - int(x) % k, input().split()))
	dct = Counter(A)
	if dct[k] == n:
		print(0)
		continue
	del dct[k]
	M = e = 0
	for c in dct:
		M = max(M, dct[c])
	for c in dct:
		if dct[c] == M:
			e = max(e, c)
	print(k * (M - 1) + e + 1)


for T in range(int(input())):
	(n, k) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	for i in range(n):
		if l[i] % k:
			l[i] = k - l[i] % k
		else:
			l[i] = 0
	(x, f) = (0, 1)
	l.sort()
	s = set()
	for i in range(n):
		if l[i] == 0:
			continue
		if l[i] in s:
			if i != 0 and l[i - 1] == l[i]:
				ele = l[i] + k * f
				x = max(x, ele)
				s.add(ele)
				f += 1
		else:
			s.add(l[i])
			x = max(x, l[i])
		if i != 0 and l[i - 1] != l[i] and (f != 1):
			f = 1
	x += x != 0
	print(x)


from collections import defaultdict as dfd

def res(a, k):
	d = dfd(int)
	for i in a:
		if i % k != 0:
			d[k - i % k] += 1
	m = 0
	ind = 0
	for i in d:
		if d[i] >= m:
			if m == d[i] and i > ind or m < d[i]:
				ind = i
			m = d[i]
	return max(0, ind + 1 + k * (m - 1))
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	print(res(a, k))


import sys
input = sys.stdin.readline
from collections import *
t = int(input())
for _ in range(t):
	(n, K) = map(int, input().split())
	a = list(map(int, input().split()))
	cnt = defaultdict(int)
	for ai in a:
		cnt[ai % K] += 1
	ans = 0
	for (k, v) in cnt.items():
		if k == 0:
			continue
		ans = max(ans, K - k + K * (v - 1) + 1)
	print(ans)


from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = Counter(map(lambda x: (k - int(x) % k) % k, input().split()))
	nax = 0
	for i in a.keys():
		if i:
			nax = max(nax, i + (a[i] - 1) * k)
	print(nax + 1 if nax else 0)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	d = {}
	for i in arr:
		if i % k != 0:
			if k - i % k not in d:
				d[k - i % k] = 1
			else:
				d[k - i % k] += 1
	ma = 0
	for i in d:
		ma = max(ma, i + d[i] * k - k + 1)
	print(ma)


from collections import deque
import bisect
from sys import stdin
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	list1 = list(map(int, input().split()))
	for i in range(n):
		if list1[i] % k != 0:
			list1[i] = list1[i] % k
			list1[i] = k - list1[i]
		else:
			list1[i] = 0
	dict1 = {}
	for i in range(n):
		if list1[i]:
			if list1[i] in dict1:
				dict1[list1[i]] += 1
			else:
				dict1[list1[i]] = 1
	ll = []
	for i in dict1:
		x = dict1[i]
		c = 0
		for j in range(x):
			ll.append(i + c)
			c += k
	ll.sort()
	x = 0
	c = 0
	for i in range(len(ll)):
		c += ll[i] - x + 1
		x = ll[i] + 1
	print(c)


test_case = int(input())
for _ in range(test_case):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	mp = {}
	for i in ar:
		calc = i % k
		if calc:
			calc = k - calc
			mp.setdefault(calc, 0)
			mp[calc] += 1
	if len(mp) == 0:
		print(0)
		continue
	max_value_key = max(mp, key=lambda k: mp[k])
	max_value_key = mp[max_value_key]
	val = 0
	for (key, value) in mp.items():
		if value == max_value_key:
			val = max(key, val)
	max_value_key = val
	print((mp[max_value_key] - 1) * k + max_value_key + 1)


for t in range(int(input())):
	(n, k) = map(int, input().split(' '))
	ar = list(map(lambda x: int(x) % k, input().split(' ')))
	r = 0
	count = 0
	ar.sort()
	ar = [0] + ar
	for i in range(n + 1):
		if ar[i] != 0:
			if ar[i] != ar[i - 1]:
				count = max(count, r)
				r = k - ar[i]
			else:
				r += k
	count = max(count, r)
	if count == 0:
		print(0)
	else:
		print(1 + count)


q = int(input())
for Q in range(q):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = (k - a[i] % k) % k
	a.sort()
	for i in range(1, n):
		if a[i] == 0:
			continue
		if a[i] % k == a[i - 1] % k:
			a[i] = a[i - 1] + k
	res = max(a)
	if res == 0:
		print(0)
	else:
		print(res + 1)


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = a[i] % k
	a = sorted(a)
	r = 0
	w = 0
	for i in range(n):
		if a[i] != 0:
			break
	d = dd(int)
	for i in a[i:]:
		d[i] += 1
	for i in d:
		if r < d[i]:
			r = d[i]
			w = i
	if w == 0:
		print(0)
	else:
		e = a.count(w)
		print(k * (e - 1) + (k - w + 1))


from collections import defaultdict

def solve():
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	extra = defaultdict(int)
	for i in a:
		out = i % k
		extra[out] += 1
	max_num = 0
	for (index, val) in extra.items():
		if index != 0:
			num = k - index + k * (val - 1)
			if num > max_num:
				max_num = num
	if max_num == 0:
		print(0)
	else:
		print(max_num + 1)
t = int(input())
for test in range(t):
	solve()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lst = [int(x) for x in input().split()]
	d = {}
	for i in lst:
		d[i % k] = d.get(i % k, 0) + 1
	try:
		d.pop(0)
	except:
		pass
	if d != {}:
		mx = max(d.values())
		res = []
		for (i, j) in d.items():
			if j == mx:
				res.append(k - i)
				x = k - i
				for i in range(mx - 1):
					res.append(x + k)
					x += k
		print(max(res) + 1)
	else:
		print(0)


from math import ceil
t = int(input())
while t:
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	mem = {}
	for ele in a:
		if ele % k == 0:
			continue
		else:
			val = k * ceil(ele / k) - ele
			if val in mem:
				mem[val] += 1
			else:
				mem[val] = 1
	maxi = 0
	for key in mem.keys():
		maxi = max(maxi, key + (mem[key] - 1) * k)
	if maxi == 0:
		print(maxi)
	else:
		print(maxi + 1)
	t -= 1


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	ai = list(map(int, input().split()))
	ai = [(k - ai[i] % k) % k for i in range(n)]
	ai.sort()
	num = 1
	ans = 1
	ans2 = ai[-1] + 1 - (ai[-1] == 0)
	for j in range(n):
		if ai[j] != 0:
			break
	j += 1
	for i in range(j, n):
		num *= int(ai[i] == ai[i - 1])
		num += 1
		if num >= ans:
			ans = num
			ans2 = ai[i] + 1
	print((ans - 1) * k + ans2)


t = int(input())
for m in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = 0
	vd = 0
	d = dict()
	rem = list()
	for i in range(n):
		vd = k - a[i] % k
		if vd not in d.keys():
			d[vd] = 1
		else:
			d[vd] += 1
		if a[i] % k != 0:
			rem.append(vd + (d[vd] - 1) * k)
		else:
			rem.append(0)
	ans = max(rem)
	if ans == 0:
		print(ans)
	else:
		print(ans + 1)


def solve():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = [(k - a[i] % k) * int(a[i] % k != 0) for i in range(n)]
	b.sort()
	b.append(-1)
	if b[-2] == 0:
		print(0)
	else:
		count = 0
		dif = 0
		j = 0
		while j < n and b[j] == 0:
			j += 1
		dif = n - j + b[j] - 1
		lenn = 1
		answ = 0
		for i in range(j, n):
			if b[i] == b[i + 1]:
				lenn += 1
			else:
				answ = max(answ, b[i] + (lenn - 1) * k + 1)
				lenn = 1
		answ = max(answ, dif)
		print(answ)
t = int(input())
for _ in range(t):
	solve()


from collections import Counter

def foo(l1):
	num = list(Counter(l1).items())
	ans = 0
	for i in range(len(num)):
		ans = max(ans, k * (num[i][1] - 1) + num[i][0])
	return ans + 1
t = int(input())
for m in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	count = 0
	l1 = []
	for i in range(n):
		if l[i] % k != 0:
			l1.append(k - l[i] % k)
	if not l1:
		print(0)
	else:
		answer = foo(l1)
		print(answer)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [k - int(K) % k for K in input().split()]
	d = {}
	for i in a:
		if i != k:
			d[i] = d.get(i, 0) + 1
	maxi = 0
	for i in d:
		if d[i] > maxi:
			maxi = d[i]
			ind = i
		elif d[i] == maxi:
			if ind < i:
				ind = i
	if maxi == 0:
		print(0)
	else:
		print((maxi - 1) * k + ind + 1)


TC = int(input())
for tc in range(TC):
	(N, K) = map(int, input().split())
	A = list(map(lambda x: int(x) % K, input().split()))
	M = {0: -1}
	for a in A:
		if a != 0:
			if a in M:
				M[a] += K
			else:
				M[a] = K - a
	print(max(M.values()) + 1)


from sys import stdin, stdout
t = int(stdin.readline().strip())
for _ in range(t):
	(n, k) = stdin.readline().strip().split(' ')
	(n, k) = (int(n), int(k))
	arr = list(map(int, stdin.readline().strip().split(' ')))
	d = {}
	for i in arr:
		key = (k - i % k) % k
		if key in d:
			d[key] += 1
		else:
			d[key] = 1
	m = 0
	ind = 0
	for i in d:
		if i != 0:
			if d[i] > m:
				m = d[i]
				ind = i
			if d[i] == m:
				if i > ind:
					ind = i
	if m == 0 and ind == 0:
		ans = 0
	else:
		ans = (m - 1) * k + ind + 1
	stdout.write(str(ans) + '\n')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	maxx = dict()
	s = []
	for i in a:
		if i % k != 0:
			s.append(k - i % k)
			if maxx.get(k - i % k) is None:
				maxx[k - i % k] = k - i % k
			else:
				maxx[k - i % k] += k
	if len(maxx.keys()) == 0:
		print(0)
	else:
		print(max(maxx.values()) + 1)


from collections import Counter
testCases = int(input())
for _ in range(testCases):
	(n, k) = list(map(int, input().split()))
	nums = list(map(int, input().split()))
	nums = list(map(lambda x: k - x % k if x % k != 0 else 0, nums))
	nums = dict(Counter(nums))
	count = 0
	for (key, value) in nums.items():
		temp = key + (value - 1) * k if key != 0 else 0
		count = max(temp, count)
	print(count + 1 if count != 0 else 0)


outputs = []
for __ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	A = list(filter(lambda y: y % k != 0, A))
	d = {}
	for i in A:
		num = k - i % k
		d[num] = d.get(num, 0) + 1
	maxm = 0
	for i in d.keys():
		if d.get(i) > 1:
			num = (d.get(i) - 1) * k + i + 1
		else:
			num = i + 1
		if maxm < num:
			maxm = num
	outputs.append(maxm)
for output in outputs:
	print(output)


from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = a[i] % k
	d = Counter(a)
	maxele = -1
	for key in d.keys():
		if key != 0:
			for i in range(d[key]):
				temp = k - key + i * k
				maxele = max(maxele, temp)
	print(maxele + 1)


from collections import defaultdict
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	m = 0
	freq = defaultdict(int)
	nums = list(map(int, input().split()))
	for n in nums:
		freq[n % k] += 1
		if n % k != 0:
			m = max(m, (freq[n % k] - 1) * k + (k - n % k) + 1)
	print(m)


from collections import Counter
import sys

def Most_Common(lst):
	data = Counter(lst)
	return data.most_common(2)
t = int(input())
while t:
	s = sys.stdin.readline().split()
	(n, k) = (int(s[0]), int(s[1]))
	lst = sys.stdin.readline().split()
	j = 0
	while j < len(lst):
		lst[j] = int(lst[j]) % k
		j += 1
	lst.sort()
	lst2 = Most_Common(lst)
	if lst2[0][0] == 0:
		if len(lst2) == 1:
			print(0)
			t -= 1
			continue
		x = lst2[1][1]
		y = lst2[1][0]
	else:
		x = lst2[0][1]
		y = lst2[0][0]
	ans = (x - 1) * k + (k - y)
	print(ans + 1)
	t -= 1


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = {}
	for i in range(n):
		c = -a[i] % k
		if c != 0:
			if c not in b:
				b[c] = 0
			b[c] += 1
	mx = -1
	v = 1
	for el in b:
		if v < b[el]:
			v = b[el]
			mx = el
		elif v == b[el] and mx < el:
			mx = el
	print((v - 1) * k + mx + 1)


class Solution:

	def __init__(self):
		(self.n, self.k) = [int(x) for x in input().split()]
		self.a = [int(x) for x in input().split()]

	def solve_and_print(self):
		(k, x) = (self.k, 0)
		liste = sorted(((k - ai % k) % k for ai in self.a if ai % k))
		last = multiple = 0
		n = len(liste)
		for i in range(1, n):
			if liste[i] == liste[i - 1]:
				multiple += 1
			else:
				last = max(last, liste[i - 1] + multiple * k)
				multiple = 0
		if n:
			last = max(last, liste[n - 1] + multiple * k)
		if last:
			last += 1
		print(last)
for _ in range(int(input())):
	Solution().solve_and_print()


def one_case():
	(n, kk) = map(int, input().split())
	a = [int(x) for x in input().split()]
	d = {}
	for i in a:
		m = i % kk
		if m in d:
			d[m] += 1
		else:
			d[m] = 1
	(mk, mv) = (1, 0)
	for (k, v) in d.items():
		if k == 0:
			continue
		if mv < v or (mv == v and mk > k):
			(mk, mv) = (k, v)
	print((mv - 1) * kk + kk - mk + 1)
t = int(input())
for i in range(t):
	one_case()


from collections import Counter
for test in range(int(input())):
	(n, k) = list(map(int, input().split()))
	lst = list(map(int, input().split()))
	arr = []
	for i in range(n):
		div = lst[i] // k + 1
		if lst[i] / k == lst[i] // k:
			toadd = 0
		else:
			toadd = k * div - lst[i]
		arr.append(toadd)
	arr = dict(Counter(arr))
	res = 0
	for r in arr:
		if r != 0:
			res = max(res, k * (arr[r] - 1) + r + 1)
	print(res)


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = 1
t = int(stdin.readline())
for _ in range(t):
	(n, k) = list(map(int, stdin.readline().rstrip().split()))
	a = list(map(int, stdin.readline().rstrip().split()))
	x = []
	d = {}
	mx = 0
	for i in range(n):
		if k - a[i] % k not in d:
			d[k - a[i] % k] = 0
		d[k - a[i] % k] += 1
		if a[i] % k != 0:
			tmp = d[k - a[i] % k] * k - a[i] % k
			x.append(tmp)
			mx = max(mx, tmp)
		else:
			x.append(0)
	if mx != 0:
		print(mx + 1)
	else:
		print(mx)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = a[i] % k
	a.sort()
	p = 0
	while a[p] == 0:
		p += 1
		if p == n:
			break
	x = 0
	i = n - 1
	while i >= p:
		pre = k - a[i]
		j = i - 1
		if j > -1:
			while a[j] == a[i]:
				pre += k
				j -= 1
				if j < p:
					break
		x = max(x, pre)
		i = j
	if x == 0:
		print(0)
	else:
		print(x + 1)


from collections import Counter

def main():
	t = Iint()
	for _ in range(t):
		(n, k) = Imap()
		counter = Counter(sorted([(k - i % k) % k for i in Ilist()]))
		x = 0
		iter = 0
		while True:
			count = 0
			rem = []
			for c in counter:
				key = c
				val = counter[c]
				if val * key == 0:
					rem.append(key)
					continue
				count += 1
				if key + iter == x:
					x += 1
					counter[c] -= 1
				elif key + iter > x:
					x = key + iter + 1
					counter[c] -= 1
				if counter[c] == 0:
					rem.append(key)
			if count == 0:
				break
			for r in rem:
				counter.pop(r)
			iter += k
		print(x)
FIO = True

def Iint():
	return int(input())

def Ilist():
	return list(map(int, input().split()))

def Imap():
	return map(int, input().split())
if FIO:
	from io import BytesIO, IOBase
	import sys
	import os
en = enumerate
if not FIO:
	if __name__ == '__main__':
		main()
		exit()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
while n > 0:
	(l, d) = input().split()
	(l, d) = (int(l), int(d))
	arr = [int(x) for x in input().split()]
	for i in range(len(arr)):
		arr[i] = (d - arr[i] % d) % d
	lookup = dict()
	for ele in arr:
		if ele not in lookup:
			lookup[ele] = 1
		else:
			lookup[ele] += 1
	rev = dict()
	for k in lookup:
		v = lookup[k]
		if v not in rev:
			rev[v] = [k]
		else:
			rev[v].append(k)
	item = rev.items()
	items = sorted(item, reverse=True)
	ans = 0
	for (k, v) in items:
		v.sort()
		if len(v) == 1 and v[0] == 0:
			continue
		else:
			ans = (k - 1) * d + v[len(v) - 1] + 1
		break
	print(ans)
	n -= 1


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().rstrip().split()))
	a = list(map(int, input().rstrip().split()))
	xval = []
	d = {}
	for i in range(n):
		if k - a[i] % k not in d.keys():
			d[k - a[i] % k] = 1
		else:
			d[k - a[i] % k] += 1
		if a[i] % k != 0:
			temp = d[k - a[i] % k] * k - a[i] % k
			xval.append(temp)
		else:
			xval.append(0)
	xval.sort()
	req = 0
	if sum(xval) != 0:
		print(xval[-1] + 1)
	else:
		print(0)


for test in range(int(input())):
	(n, k) = map(int, input().split())
	mod = {}
	for i in list(map(int, input().split())):
		tmp = i % k
		if tmp in mod:
			mod[tmp] += 1
		else:
			mod[tmp] = 1
	mod[0] = 0
	max_value = max(mod.values())
	final_dict = [k for (k, v) in mod.items() if v == max_value]
	key_max_value = min(final_dict)
	ans = (max_value - 1) * k + (k - key_max_value) + 1
	if key_max_value == 0:
		ans -= 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	addA = []
	for elem in a:
		if elem % k == 0:
			continue
		else:
			addA.append(k - elem % k)
	maxAddition = 0
	addA.sort()
	count = 0
	lastelem = -1
	for elem in addA:
		if lastelem == -1:
			lastelem = elem
			count = 1
		elif elem != lastelem:
			if maxAddition < (count - 1) * k + lastelem + 1:
				maxAddition = (count - 1) * k + lastelem + 1
			count = 1
			lastelem = elem
		else:
			count += 1
	if maxAddition < (count - 1) * k + lastelem + 1:
		maxAddition = (count - 1) * k + lastelem + 1
	print(maxAddition)


t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	frecuency = dict()
	for x in a:
		remainder = x % k
		if remainder != 0:
			frecuency[k - remainder] = frecuency.get(k - remainder, 0) + 1
	max_loops = [0, 0]
	for (key, value) in frecuency.items():
		if value > max_loops[0]:
			max_loops[0] = value
			max_loops[1] = key
		elif value == max_loops[0] and key > max_loops[1]:
			max_loops[1] = key
	if max_loops[0] == 0 and max_loops[0] == 0:
		print(0)
	else:
		print(k * max(max_loops[0] - 1, 0) + max_loops[1] + 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	l = []
	mn = min
	d = {}
	flag = 1
	for i in a:
		if i % k > 0:
			tmp = k - i % k
			d[tmp] = d.get(tmp, 0) + 1
			flag = 0
	l = d.keys()
	l = sorted(l)
	x = 0
	ans = 0
	ll = len(l)
	ik = 0
	while flag == 0:
		flag = 1
		for p in range(ll):
			i = l[p] - k * ik
			if d[i] > 0:
				ans += l[p] - x
				d[i] -= 1
				x += l[p] - x
				flag = 0
			l[p] += k
		ik += 1
	if ans > 0:
		ans += 1
	print(ans)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	data = list(map(int, input().split()))
	process = dict()
	x = 0
	for j in range(n):
		try:
			process[k - data[j] % k] += 1
		except:
			process[k - data[j] % k] = 1
	try:
		process.pop(k)
	except:
		pass
	if not process:
		print(0)
		continue
	max_len = 0
	max_value = 0
	for j in process.keys():
		if process[j] > max_len:
			max_len = process[j]
			max_value = j
		if process[j] == max_len and j > max_value:
			max_value = j
	print((max_len - 1) * k + max_value + 1)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	x = list(map(int, input().split()))
	q = []
	for i in x:
		if k - i % k != k:
			q.append(k - i % k)
	q.sort()
	if len(q) == 0:
		print(0)
	else:
		c = q[0]
		for i in range(1, len(q)):
			if q[i] == c:
				q[i] = k + q[i - 1]
			else:
				c = q[i]
		print(max(q) + 1)


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	ans = 0
	dic = {}
	for i in a:
		x = (k - i) % k
		if x == 0:
			continue
		if x in dic.keys():
			dic[x] += 1
		else:
			dic[x] = 1
	m = 1
	c = -1
	ans = 0
	ma = {}
	for i in dic.keys():
		if dic[i] > m or (dic[i] == m and i > c):
			m = dic[i]
			c = i
	else:
		print(k * (m - 1) + c + 1)


from collections import deque
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from bisect import bisect_left as bl
from math import log2, ceil
from itertools import permutations

def main():
	for t in range(int(input())):
		(n, k) = [int(j) for j in input().split()]
		l = [int(j) for j in input().split()]
		d = dict()
		av = dict()
		for i in range(n):
			if k - l[i] % k in d:
				d[k - l[i] % k] += 1
			else:
				d[k - l[i] % k] = 1
		a = list(d.items())
		ans = 0
		for i in a:
			mod = i[0]
			if mod > 0 and mod < k:
				ans = max(ans, k * (i[1] - 1) + i[0] + 1)
		print(ans)
main()


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

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

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

def invr():
	return map(int, input().split())
n = inp()
for i in range(n):
	l = inlt()
	x = l[0]
	k = l[1]
	l = inlt()
	d = {}
	for j in range(x):
		p = l[j] % k
		if p in d:
			d[p] += 1
		else:
			d[p] = 1
	repeated = 0
	val = 0
	for j in d:
		if j == 0:
			continue
		if d[j] > repeated or (d[j] == repeated and j < val):
			val = j
			repeated = d[j]
	res = k * repeated
	if val != 0:
		res = res - val + 1
		print(res)
	else:
		print(0)


from collections import Counter
from sys import stdin, stdout

def input():
	return stdin.readline().strip()

def ans(A, K):
	A = [a % K for a in A if a % K > 0]
	if len(A) == 0:
		return 0
	A = Counter(A)
	ret = float('-inf')
	for cc in A:
		ret = max(ret, (A[cc] - 1) * K + K - cc + 1)
	return ret
T = int(input())
for _ in range(T):
	(N, K) = input().split(' ')
	K = int(K)
	A = input().split(' ')
	A = list(map(int, A))
	print(ans(A, K))


from collections import deque, defaultdict

def find_distance_to_nearest_greater_multiple(number, k):
	remains = number % k
	if remains == 0:
		return 0
	distance = k - remains
	return distance

def find_moves_to_reach(start, end):
	return end - start
t = int(input())
while t > 0:
	(n, k) = map(int, input().strip().split())
	numbers = list(map(int, input().strip().split()))
	diffs_to_reach_nearest_k_multiple = defaultdict(int)
	for number in numbers:
		diff = find_distance_to_nearest_greater_multiple(number, k)
		diffs_to_reach_nearest_k_multiple[diff] += 1
	if 0 in diffs_to_reach_nearest_k_multiple:
		del diffs_to_reach_nearest_k_multiple[0]
	diffs_and_items = list(diffs_to_reach_nearest_k_multiple.items())
	diffs_and_items.sort()
	diffs_queue = deque(diffs_and_items)
	x = 0
	while len(diffs_queue) > 0:
		(diff, items_remaining) = diffs_queue.popleft()
		moves_to_reach_here = find_moves_to_reach(x, diff)
		x += moves_to_reach_here + 1
		items_remaining -= 1
		if items_remaining > 0:
			diffs_queue.append((diff + k, items_remaining))
	print(x)
	t -= 1


for x in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	ans = 0
	mod = []
	for i in l:
		if i % k == 0:
			mod += [0]
		else:
			mod += [k - i % k]
	mod.sort()
	cnt = 1
	mod1 = [mod[0]]
	for i in range(1, n):
		if mod[i] == mod[i - 1] and mod[i] != 0:
			cnt += 1
		else:
			cnt = 1
		mod1 += [mod[i] + (cnt - 1) * k]
	mod1.sort()
	ans = mod1[0]
	for i in range(1, n):
		ans += mod1[i] - mod1[i - 1]
	if ans != 0:
		ans += 1
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	d = {}
	for j in l:
		r = j % k
		if r:
			if k - r in d:
				d[k - r] = d[k - r] + 1
			else:
				d[k - r] = 1
	z = float('-inf')
	for j in d:
		r = (d[j] - 1) * k + j
		if r > z:
			z = max(z, r)
	print(max(z + 1, 0))


def ans():
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	a = [int(x) for x in input().split()]
	for i in range(n):
		a[i] = a[i] % k
		if a[i] != 0:
			a[i] = k - a[i]
	a.sort()
	for i in range(1, n):
		if a[i] % k == 0:
			pass
		elif a[i] % k == a[i - 1] % k:
			a[i] = a[i - 1] + k
		else:
			pass
	a.sort()
	if a[-1] == 0:
		print(0)
		return
	print(a[-1] + 1)
t = int(input())
for i in range(t):
	ans()


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left
from bisect import bisect_right

def L():
	return list(map(int, stdin.readline().split()))

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())
P = 1000000007

def main():
	for t in range(I()):
		(n, k) = In()
		arr = L()
		dict1 = {}
		for i in arr:
			if i % k:
				if k - i % k not in dict1.keys():
					dict1[k - i % k] = 1
				else:
					dict1[k - i % k] += 1
		count = 0
		for i in dict1:
			count = max(count, (dict1[i] - 1) * k + i)
		if count:
			count += 1
		print(count)
main()


from sys import stdin
for _ in range(int(stdin.readline())):
	(n, k) = list(map(int, stdin.readline().split()))
	a = list(map(int, stdin.readline().split()))
	d = {}
	res = 0
	for (i, v) in enumerate(a):
		if v % k == 0:
			continue
		else:
			t = k - v % k
			if t not in d:
				d[t] = 0
			else:
				d[t] += 1
			if d[t] * k + t > res:
				res = d[t] * k + t
	if res == 0:
		print(res)
	else:
		print(res + 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(map(int, input().split()))
	ll = []
	for i in s:
		if i % k != 0:
			ll.append(i)
	for i in range(0, len(ll)):
		ll[i] = ll[i] % k
	if len(ll) == 0:
		print(0)
		continue
	ll.sort()
	ans = 0
	x = -1
	maxy = 0
	mycount = dict()
	for i in ll:
		if i in mycount.keys():
			mycount[i] += 1
		else:
			mycount[i] = 1
	for i in ll:
		if maxy < mycount[i]:
			x = i
			maxy = mycount[i]
	ans = k * (maxy - 1) + k - x + 1
	print(ans)


from collections import Counter

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		A = [k - int(x) % k for x in input().split() if int(x) % k != 0]
		if A == []:
			print(0)
			continue
		c = Counter(A).most_common()
		v0 = c[0][1]
		c = sorted([(k, v) for (k, v) in c if v == v0], key=lambda x: x[0], reverse=True)
		print(k * (v0 - 1) + c[0][0] + 1)
main()


from collections import defaultdict, Counter, deque
import sys
import threading
from sys import stdin, stdout
sys.setrecursionlimit(1 << 30)
threading.stack_size(1 << 27)

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		nums = list(map(int, input().split()))
		sets = defaultdict(int)
		for (idx, num) in enumerate(nums):
			targ = k - num % k
			if targ != k:
				sets[targ] += 1
		maxim = [1, -1]
		for (rem, count) in sets.items():
			maxim = max(maxim, [count, rem])
		print((maxim[0] - 1) * k + maxim[1] + 1)
thread = threading.Thread(target=main)
thread.start()
thread.join()


t = int(input())
c = []
for i in range(t):
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	a = [int(i) for i in input().split()]
	d = {}
	final = 0
	for j in range(n):
		if a[j] % k != 0:
			w = a[j] % k
			if w in d:
				final = max(final, k - w + d[w] * k)
				d[w] += 1
			else:
				final = max(final, k - w)
				d[w] = 1
	if final == 0:
		c.append(final)
	else:
		c.append(final + 1)
for k in c:
	print(k)


import math
from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	need = []
	d = {}
	for i in range(n):
		if arr[i] % k != 0:
			need.append(k - arr[i] % k)
			if need[-1] not in d.keys():
				d[need[-1]] = 1
			else:
				d[need[-1]] += 1
	maxrep = 0
	maxele = 0
	if d:
		maxrep = max(d.values())
		for i in d.keys():
			if d[i] == maxrep and i >= maxele:
				maxele = i
		count = (maxrep - 1) * k + maxele + 1
		print(count)
	else:
		print(0)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		if a[i] % k == 0:
			a[i] = 0
		else:
			a[i] = k - a[i] % k
	a = sorted(a)
	x = a[0]
	y = 0
	for i in range(1, n):
		if a[i] == a[i - 1] and a[i] != 0:
			y += k
		else:
			y = 0
		x = max(x, a[i] + y)
	if x == 0:
		print(0)
	else:
		print(x + 1)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from math import gcd
from bisect import bisect
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))

def solve():
	for _ in range(int(input())):
		(n, k) = read()
		arr = read()
		dic = defaultdict(int)
		for i in arr:
			if i % k != 0:
				dic[k - i % k] += 1
		ans = 0
		for i in dic:
			ans = max(ans, i + (dic[i] - 1) * k + 1)
		print(ans)
solve()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	li = []
	for i in range(n):
		rem = ar[i] % k
		if rem != 0:
			li.append(k - rem)
	dic = {}
	for i in li:
		if i in dic:
			dic[i] += 1
		else:
			dic[i] = 1
	li = list(dic.keys())
	li.sort()
	ans = [-1]
	for i in li:
		left = dic[i] - 1
		ans.append(left * k + i)
	print(max(ans) + 1)


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
from itertools import permutations
I = sys.stdin.readline

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def valid(row, col, rows, cols, rcross, lcross):
	return rows[row] == 0 and cols[col] == 0 and (rcross[col + row] == 0) and (lcross[col - row] == 0)

def div(n):
	tmp = []
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			tmp.append(i)
			if i != n // i:
				tmp.append(n // i)
	return tmp

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				return False
		return True

def main():
	ans = ''
	for _ in range(ii()):
		(n, k) = mi()
		arr = li()
		tmp = [0] * n
		for i in range(n):
			tmp[i] = math.ceil(arr[i] / k) * k - arr[i]
		d = defaultdict(int)
		for i in tmp:
			if d[i] == 0:
				d[i] = i
			else:
				d[i] += k
		x = max(d.values())
		if x == 0:
			ans += '0\n'
		else:
			ans += str(x + 1) + '\n'
	print(ans)
main()


t = int(input())
for q in range(t):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	dic = {}
	maxi = 0
	for i in range(n):
		t = dic.get(arr[i] % k, 0)
		if arr[i] % k == 0:
			continue
		else:
			a = k - arr[i] % k + t * k
		if a > maxi:
			maxi = a
		dic[arr[i] % k] = t + 1
	if maxi != 0:
		maxi += 1
	print(maxi)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = a[i] % k
	h = dict()
	seen = False
	for i in range(n):
		if a[i] == 0:
			continue
		seen = True
		if a[i] in h:
			h[a[i]] += k
		else:
			h[a[i]] = k - a[i]
	if not seen:
		print(0)
	else:
		print(max(h.values()) + 1)


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


def main():
	for t in range(int(input())):
		(n, k) = map(int, input().split())
		a = [int(i) for i in input().split()]
		rem = {}
		for i in a:
			if i % k not in rem:
				rem[i % k] = 0
			rem[i % k] += 1
		maxAns = 0
		if 0 in rem:
			del rem[0]
		for i in rem:
			maxAns = max(maxAns, (rem[i] - 1) * k + (k - i))
		if maxAns == 0:
			print(0)
		else:
			print(maxAns + 1)
main()


def readintlst():
	return list(map(int, input().split(' ')))

def readcharlst():
	return list(input().split(' '))

def readn():
	return int(input())
from collections import Counter
for _ in range(readn()):
	(n, k) = readintlst()
	arr = readintlst()
	a = [k - x % k for x in arr if x % k != 0]
	if not a:
		print(0)
		continue
	c = Counter(a)
	v = c.most_common(1)[0][1]
	kk = -1
	for (kt, vt) in c.items():
		if vt == v:
			kk = max(kk, kt)
	print(k * (v - 1) + 1 + kk)


import sys
input = sys.stdin.readline
from collections import Counter
t = int(input())
for tests in range(t):
	(n, k) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	B = [(k - a) % k for a in A]
	C = Counter(B)
	MAX = 1
	IND = -1
	for c in C:
		if c == 0:
			continue
		if MAX < C[c]:
			MAX = C[c]
			IND = c
		elif MAX == C[c] and IND < c:
			IND = c
	print(IND + 1 + (MAX - 1) * k)


from collections import defaultdict
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = [int(j) for j in input().split()]
	c = defaultdict(int)
	for i in l:
		if i % k:
			c[k - i % k] += 1
	if len(c) == 0:
		print(0)
	else:
		d = k - len(c) - 1
		c[0] = 0
		(o, x) = (1, 1)
		l1 = [(v, k) for (k, v) in c.items()]
		l1.sort()
		index = l1[-1][1]
		m = l1[-1][0]
		o = k * (m - 1) + 1 + index
		print(o)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	final = []
	for i in lst:
		if i % k != 0:
			final.append(i % k)
	val = {}
	for i in final:
		if i not in val:
			val[i] = 1
		else:
			val[i] += 1
	temp = 0
	count = 0
	for i in val:
		if val[i] > count:
			count = val[i]
			temp = i
		elif count == val[i] and i < temp or temp == 0:
			temp = i
	if temp != 0:
		temp -= 1
	print((count - 1) * k + k - temp)


ll = lambda : list(map(int, input().split()))
st = lambda : input()
v = lambda : map(int, input().split())
ii = lambda : int(input())
from collections import *
from math import *
for _ in range(ii()):
	(n, k) = v()
	l = ll()
	c = 0
	x = 0
	res = []
	f = 0
	for i in range(n):
		if l[i] % k != 0:
			res.append(-l[i] % k)
	if len(res) == 0:
		print(0)
		continue
	d = dict(Counter(res))
	temp = list(d.items())
	temp.sort(reverse=True, key=lambda x: x[0])
	temp.sort(reverse=True, key=lambda x: x[1])
	c = temp[0][0] + (temp[0][1] - 1) * k
	print(c + 1)


from collections import Counter
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	x = 0
	n = len(l)
	for i in range(n):
		l[i] = l[i] % b
	for i in range(n):
		if l[i] != 0:
			l[i] = b - l[i]
	l.sort()
	k = set(l)
	d = Counter(l)
	mn = 0
	for i in d:
		if i == 0:
			continue
		elif mn <= d[i]:
			mn = d[i]
			element = i
	fq = mn
	if d[0] == a:
		print(0)
	else:
		print(b * (fq - 1) + 1 + element)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = dict()
	for i in range(n):
		if l[i] % k != 0:
			if l[i] > k:
				if (l[i] // k + 1) * k - l[i] not in d:
					d[(l[i] // k + 1) * k - l[i]] = 1
				else:
					d[(l[i] // k + 1) * k - l[i]] += 1
			elif k - l[i] not in d:
				d[k - l[i]] = 1
			else:
				d[k - l[i]] += 1
	ans = 0
	for x in d:
		ans = max(ans, (d[x] - 1) * k + x + 1)
	print(ans)


from math import ceil

def main(n, k, s):
	rem = {}
	for i in s:
		if rem.get(ceil(i / k) * k - i) == None:
			rem[ceil(i / k) * k - i] = 1
		else:
			rem[ceil(i / k) * k - i] += 1
	if rem.get(0):
		del rem[0]
	if rem == {}:
		return 0
	(maxF, num) = (0, -1)
	for i in rem.keys():
		if rem[i] > maxF:
			maxF = rem[i]
			num = i
		elif rem[i] == maxF:
			maxF = rem[i]
			num = max(num, i)
	return num + (k - num + num) * (maxF - 1) + 1
for i in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	s = list(map(int, input().split()))
	print(main(n, k, s))


a = input()
for x in range(int(a)):
	b = input().split(' ')
	c = input().split(' ')
	dict1 = {}
	for i in c:
		if int(i) % int(b[1]) != 0:
			tag = int(b[1]) - int(i) % int(b[1])
			if tag not in dict1:
				dict1[tag] = 1
			else:
				dict1[tag] += 1
	ans = 0
	if len(dict1) == 0:
		print(ans)
	else:
		for i in dict1:
			if dict1[i] == 1:
				ans = max(i, ans)
			else:
				tag = int(b[1]) * (dict1[i] - 1) + i
				ans = max(tag, ans)
		print(ans + 1)


for test_i in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(lambda el: (k - int(el) % k) % k, input().split()))
	rems = {}
	for el in arr:
		if el:
			if el in rems:
				rems[el] += 1
			else:
				rems[el] = 1
	if rems:
		max_rem_item = max([(item[1], item[0]) for item in rems.items()])
		print(k * (max_rem_item[0] - 1) + max_rem_item[1] + 1)
	else:
		print(0)


from collections import defaultdict
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	v = list(map(int, input().split()))
	checked = defaultdict(bool)
	maior = float('-inf')
	memory = defaultdict(lambda : -1)
	for x in v:
		if x % k == 0:
			maior = max(maior, 0)
			continue
		else:
			resto = (x // k + 1) * k - x
			soma = resto
			while memory[soma] != -1:
				soma = memory[soma] + k
			while checked[soma]:
				soma += k
			memory[resto] = soma
			checked[soma] = True
			maior = max(maior, soma)
	print(maior + 1 if maior > 0 else 0)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = []
	for i in range(n):
		c = (k - a[i] % k) % k
		b.append(c)
	c = {}
	for i in range(len(b)):
		if b[i] != 0:
			if b[i] in c.keys():
				c[b[i]] += 1
			else:
				c[b[i]] = 1
	s = []
	for i in c:
		s.append(k * (c[i] - 1) + i)
	if len(s) == 0:
		print(0)
	else:
		print(max(s) + 1)


import sys
input = sys.stdin.readline
(inp, ip) = (lambda : int(input()), lambda : [int(w) for w in input().split()])
for _ in range(inp()):
	(n, k) = ip()
	x = ip()
	d = []
	for i in range(n):
		t = x[i] % k
		if t:
			d.append(k - t)
	if d == []:
		print(0)
		continue
	dt = {}
	for i in d:
		dt[i] = dt.get(i, 0) + 1
	vis = {}
	for j in sorted(dt):
		i = j
		for ii in range(dt[j]):
			flag = 0
			while not vis.get(i, 1):
				i += k
			vis[i] = 0
			i += k
	print(max(vis) + 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split(' ')))
	N = len(arr)
	m = {}
	ans = 0
	for i in range(N):
		if arr[i] % k:
			m[k - arr[i] % k] = m.get(k - arr[i] % k, 0) + 1
	flag = False
	for s in m:
		flag = True
		ans = max(ans, k * (m[s] - 1) + s)
	if flag:
		ans += 1
	print(ans)


for _ in ' ' * int(input()):
	(a, b) = map(int, input().split())
	d = dict()
	for i in map(int, input().split()):
		if i % b:
			d[b - i % b] = d.get(b - i % b, 0) + 1
	if len(d) == 0:
		print(0)
		continue
	s = 0
	s1 = 0
	for i in sorted(d, reverse=True):
		if d[i] > s:
			s = d[i]
			s1 = i
	print(b * (s - 1) + s1 + 1)


import sys
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	for i in range(n):
		b = a[i] % k
		if b == 0:
			continue
		if b not in d.keys():
			d[b] = 1
		else:
			d[b] += 1
	if len(d) == 0:
		print(0)
		continue
	m = max(d.values())
	c = sys.maxsize
	for i in d.keys():
		if d[i] == m and i < c:
			c = i
	t = k * d[c] - c + 1
	print(t)


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().strip().split()))
	list1 = list(map(int, input().strip().split()))
	for i in range(len(list1)):
		if list1[i] % k == 0:
			list1[i] = 0
		else:
			list1[i] = k - list1[i] % k
	m = dict()
	for i in range(len(list1)):
		if list1[i] in m:
			m[list1[i]] += 1
		else:
			m[list1[i]] = 1
	max = 0
	for value in m:
		val = m.get(value)
		if value == 0:
			temp = 0
		else:
			temp = value + 1 + k * (val - 1)
		if temp > max:
			max = temp
	print(max)


from collections import defaultdict
for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		if a[i] % k != 0:
			a[i] = k - a[i] % k
		else:
			a[i] = 0
	m = defaultdict(int)
	for i in range(n):
		if a[i] == 0:
			pass
		elif m[a[i]] == 0:
			m[a[i]] += 1
		else:
			if m[a[i]] != 0:
				m[a[i]] += 1
				a[i] += k * (m[a[i]] - 1)
			m[a[i]] += 1
	if max(a) == 0:
		print(0)
	else:
		print(max(a) + 1)


from collections import defaultdict

def get_array():
	arr = input().split(' ')
	return [int(el) for el in arr]

def normalize_array(array, divider):
	remaining = defaultdict(lambda : 0)
	cycles = 0
	for n in array:
		if n % divider != 0:
			key = divider - n % divider
			remaining[key] += 1
			cycles = max(cycles, remaining[key])
	rest = 0
	for r in remaining:
		if remaining[r] == cycles:
			rest = max(rest, r + 1)
	return max((cycles - 1) * divider, 0) + rest
solutions = []
for _ in range(int(input())):
	(_, k) = get_array()
	numbers = get_array()
	solutions.append(str(normalize_array(numbers, k)))
print('\n'.join(solutions))


import math
from collections import deque, Counter, defaultdict

def main():
	t = Iint()
	for _ in range(t):
		(n, k) = Imap()
		a = Counter([(k - i % k) % k for i in Ilist()])
		a = [[k, v] for (k, v) in zip(a.keys(), a.values())]
		a.sort()
		x = 0
		iter = 0
		while True:
			count = 0
			for ai in a:
				if ai[1] == 0 or ai[0] == 0:
					continue
				count += 1
				if ai[0] + iter == x:
					x += 1
					ai[1] -= 1
				elif ai[0] + iter > x:
					x = ai[0] + iter + 1
					ai[1] -= 1
			if count == 0:
				break
			iter += k
		print(x)
FIO = True

def I():
	return input()

def Iint():
	return int(input())

def Ilist():
	return list(map(int, input().split()))

def Imap():
	return map(int, input().split())

def Plist(li, s=' '):
	print(s.join(map(str, li)))
if FIO:
	from io import BytesIO, IOBase
	import sys
	import os
en = enumerate
if not FIO:
	if __name__ == '__main__':
		main()
		exit()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


import sys
import collections

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def main(n, A, k):
	record = collections.defaultdict(int)
	res = 0
	for a in A:
		mod = a % k
		if mod != 0:
			record[k - mod] += 1
	for key in record:
		res = max(res, key + (record[key] - 1) * k + 1)
	print(res)
	return res
N = int(input())
for i in range(N):
	(n, k) = get_ints()
	A = get_list()
	main(n, A, k)


from fractions import Fraction
import bisect
import os
import io
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
from queue import Queue

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
t = 1
t = iinput()
for _ in range(t):
	(n, k) = rinput()
	a = rlinput()
	newa = []
	for i in a:
		if i % k != 0:
			newa.append(i)
	n = len(newa)
	d = defaultdict(int)
	for i in newa:
		d[i % k] += 1
	ans = 0
	for i in d:
		ans = max(ans, (d[i] - 1) * k + (k - i) + 1)
	print(ans)


import math
import os
import random
import re
import sys
from collections import defaultdict
case = int(input())
for i in range(case):
	a = [int(x) for x in input().split()]
	(n, k) = (a[0], a[1])
	ara = [int(x) for x in input().split()]
	for i in range(len(ara)):
		if ara[i] % k == 0:
			ara[i] = 0
		elif ara[i] <= k:
			ara[i] = k - ara[i]
		else:
			ara[i] = k * (ara[i] // k + 1) - ara[i]
	ara = sorted(ara)
	newAra = []
	cont = 1
	if ara[0] != 0:
		newAra.append(ara[0])
	while True:
		for i in range(1, len(ara)):
			if ara[i] != 0:
				if ara[i] == ara[i - 1]:
					newAra.append(ara[i] + k * cont)
					cont += 1
				else:
					newAra.append(ara[i])
					cont = 1
		if len(newAra) == 0:
			print(0)
			break
		if len(set(newAra)) == len(newAra):
			print(max(newAra) + 1)
			break
		ara = newAra
		newAra = []
		cont = 1


from collections import Counter
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	a = []
	for i in range(n):
		if l[i] % k == 0:
			a.append(l[i] // k * k)
		else:
			a.append(l[i] // k * k + k)
	for i in range(n):
		a[i] = a[i] - l[i]
	d = Counter(a)
	for i in range(n):
		if a[i] == 0:
			continue
		else:
			a[i] = a[i] + (d[a[i]] - 1) * k
	if max(a) == 0:
		print(0)
	else:
		print(max(a) + 1)


import os
os_input = os.read(0, int(10000000.0)).split()
os_input_pos = -1
answer_list = []

def read_s():
	global os_input_pos
	os_input_pos += 1
	return os_input[os_input_pos].decode()

def read_i():
	return int(read_s())

def write_s(v):
	answer_list.append(v)

def write_i(v):
	write_s(str(v))

def print_ans():
	os.write(1, '\n'.join(answer_list).encode())
	os.write(1, '\n'.encode())
from itertools import groupby
T = read_i()
while T:
	T -= 1
	n = read_i()
	k = read_i()
	a = sorted([read_i() % k for i in range(n)])
	ans = max([k - rem + 1 + k * (len(list(g)) - 1) for (rem, g) in groupby(a) if rem != 0], default=0)
	write_i(ans)
print_ans()


def sel(a, b):
	z = [[] for i in range(b + 1)]
	for i in a:
		z[i[1]] += [i[0]]
	for i in range(b, 0, -1):
		if z[i]:
			return [i, max(z[i])]
from collections import Counter
for _ in ' ' * int(input()):
	d = []
	(a, b) = map(int, input().split())
	for i in map(int, input().split()):
		k = i % b
		if k:
			d.append(b - k)
	if len(d) == 0:
		print(0)
	else:
		z = sorted(Counter(d).most_common())
		(g, h) = sel(z, a)
		print(1 + h + (g - 1) * b)


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
t = int(input())
while t:
	(x, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = dd(int)
	for i in l:
		d[i % k] += 1
	mx = 0
	for i in d:
		if i == 0:
			continue
		mx = max(mx, k - i + (d[i] - 1) * k + 1)
	print(mx)
	t -= 1


tot = int(input().strip())
while tot > 0:
	(n, k) = [int(x) for x in input().strip().split(' ')]
	a = [int(x) for x in input().strip().split(' ')]
	ans = 0
	d = {}
	for x in a:
		if x % k != 0:
			if x > k:
				v = (x // k + 1) * k - x
				if v not in d:
					d[v] = v
				else:
					d[v] += k
			else:
				v = k - x
				if v not in d:
					d[v] = v
				else:
					d[v] += k
	if not d:
		print(0)
	else:
		print(max(d.values()) + 1)
	tot -= 1


t = int(input())
for hatt in range(t):
	lis = input().split()
	(n, k) = (int(lis[0]), int(lis[1]))
	lis = input().split()
	a = [0] * n
	for i in range(n):
		num = int(lis[i])
		rem = num % k
		if rem > 0:
			rem = k - rem
		a[i] = rem
	a.sort()
	i = 0
	while i < n and a[i] == 0:
		i += 1
	if i == n:
		print(0)
	else:
		maxrep = 1
		maxrepmod = a[i]
		prev = a[i]
		currrep = 1
		i += 1
		while i < n:
			if a[i] == prev:
				currrep += 1
			else:
				prev = a[i]
				currrep = 1
			if currrep >= maxrep:
				maxrep = currrep
				maxrepmod = a[i]
			i += 1
		print(1 + maxrepmod + (maxrep - 1) * k)


t = int(input())
from collections import Counter
for case in range(t):
	(n, k) = list(map(int, input().split()))
	a = [int(x) for x in input().split()]
	w = Counter((x % k for x in a))
	v = 0
	for (x, freq) in list(w.items()):
		if x == 0:
			continue
		if freq == 0:
			continue
		r = -x % k
		v = max(v, r + (freq - 1) * k + 1)
	print(v)


t = int(input())
for _ in range(t):
	(n, k) = tuple(map(int, input().split()))
	a = sorted(list(map(lambda x: k - int(x) % k, input().split())))
	p = 0
	s = k
	for (i, el) in enumerate(a):
		if el == k:
			a[i] -= k
		elif el != p:
			s = k
			p = el
		elif el == p:
			a[i] += s
			s += k
	ans = max(a)
	if ans > 0:
		ans += 1
	print(ans)


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	nums = list(map(int, input().split()))
	a = dict()
	max_value = 0
	flag = 0
	for x in nums:
		if x % k != 0:
			x = k - x % k
			if not x in a.keys():
				a[x] = x
			else:
				a[x] += k
				x = a[x]
			max_value = max(max_value, x)
			flag = 1
	if flag == 0:
		print(0)
	else:
		print(max_value + 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a2 = sorted([a[i] % k for i in range(n) if a[i] % k != 0])
	dct = {}
	for i in a2:
		if dct.get(i, False):
			dct[i] = dct[i] + 1
		else:
			dct[i] = 1
	ans = 0
	for key in dct:
		ans = max(ans, dct[key] * k - key + 1)
	print(ans)


for _t in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = a[i] % k
	s = {}
	for i in a:
		if i == 0:
			continue
		v = k - i
		if v not in s:
			s[v] = 1
		else:
			x = v + k * s[v]
			s[v] += 1
			s[x] = 1
	if s:
		print(max(s) + 1)
	else:
		print(0)


from sys import stdin
from collections import defaultdict
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lis = list(map(int, input().split()))
	for i in lis:
		if i % k != 0:
			break
	else:
		print(0)
		continue
	for i in range(n):
		lis[i] %= k
	lis.sort(reverse=True)
	d = dict()
	for i in lis:
		if i != 0:
			d[k - i] = d.get(k - i, 0) + 1
	n = sum(d.values())
	res = []
	while len(res) != n:
		for i in d:
			if d[i] > 0:
				d[i] -= 1
				res.append(i)
	x = res[0] + 1
	for i in range(1, n):
		if res[i] - res[i - 1] <= 0:
			x += k - (res[i - 1] - res[i])
		else:
			x += res[i] - res[i - 1]
	print(x)


from sys import stdin, stdout

def main():
	t = int(stdin.readline())
	for case in range(t):
		(n, k) = map(int, stdin.readline().split())
		ary = list(map(int, stdin.readline().split()))
		rems = []
		ht = {}
		for elem in ary:
			rem = elem % k
			if str(rem) not in ht:
				ht[str(rem)] = 1
				rems.append(rem)
			else:
				ht[str(rem)] += 1
		rems = list(filter(lambda x: x > 0, rems))
		rems.sort(reverse=True)
		if rems:
			mxr = rems[0]
			for rem in rems:
				if ht[str(rem)] >= ht[str(mxr)]:
					mxr = rem
			moves = (ht[str(mxr)] - 1) * k + k - mxr + 1
		else:
			moves = 0
		stdout.write(str(moves))
		stdout.write('\n')
	return
main()


from collections import Counter
for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = Counter([i % k for i in map(int, input().split())])
	b = sorted(a.most_common(), key=lambda x: (-x[1], x[0]))
	if b[0][0]:
		print(b[0][1] * k - b[0][0] + 1)
	elif len(b) > 1:
		print(b[1][1] * k - b[1][0] + 1)
	else:
		print(0)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	di = {}
	for i in a:
		i = (k - i % k) % k
		if i == 0:
			continue
		if i in di:
			di[i] += 1
		else:
			di[i] = 1
	if not di:
		print(0)
		continue
	ma = max(di.values())
	ans = max((i for (i, j) in di.items() if j == ma)) + 1
	ans += (ma - 1) * k
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	for i in range(n):
		ar[i] = ar[i] % k
	ar.sort()
	i = 0
	ans = -1
	while i < n:
		temp = k - ar[i]
		if ar[i] == 0:
			temp = 0
			while i + 1 < n and ar[i] == 0 and (ar[i + 1] == ar[i]):
				i += 1
		else:
			while i + 1 < n and ar[i] == ar[i + 1]:
				temp = temp + k
				i += 1
		i += 1
		if ans < temp:
			ans = temp
	if ans > 0:
		print(ans + 1)
	else:
		print(ans)


from math import log2
for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	for i in range(len(a)):
		m = a[i] - (a[i] // k + 1) * k
		if -1 * m in d:
			d[-1 * m].append(a[i])
		elif a[i] / k == int(a[i] / k):
			pass
		else:
			d[-1 * m] = []
			d[-1 * m].append(a[i])
	b = 0
	c = 0
	if len(d) == 0:
		print(0)
	else:
		for (ke, v) in sorted(d.items()):
			if len(v) == b and ke > c:
				c = ke
			elif len(v) > b:
				b = len(v)
				c = ke
		print(k * (b - 1) + c + 1)


def solution(x, k):
	r = {}
	(max_cnt, max_value) = (0, 0)
	for t in x:
		if t % k != 0:
			r[k - t % k] = r.get(k - t % k, 0) + 1
			if r[k - t % k] > max_cnt:
				max_cnt = r[k - t % k]
				max_value = k - t % k
			elif r[k - t % k] == max_cnt:
				max_value = max(max_value, k - t % k)
	return max(k * (max_cnt - 1) + max_value + 1, 0)
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	x = list(map(int, input().split()))
	print(solution(x, k))


def turns(n, k, a):
	remainders_count = dict()
	majority_remainder_count = 0
	majority_remainder = k + 1
	for num in a:
		if num % k == 0:
			continue
		if num % k in remainders_count:
			remainders_count[num % k] += 1
		else:
			remainders_count[num % k] = 1
		if remainders_count[num % k] > majority_remainder_count:
			majority_remainder_count = remainders_count[num % k]
			majority_remainder = num % k
		elif remainders_count[num % k] == majority_remainder_count:
			majority_remainder = min(majority_remainder, num % k)
	if majority_remainder < k + 1:
		return (majority_remainder_count - 1) * k + (k + 1 - majority_remainder)
	else:
		return 0
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	print(turns(n, k, a))


def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		d = {}
		M = 0
		for i in a:
			if i >= k:
				m = i % k
				if m == 0:
					continue
				need = k - m
			else:
				m = k - i
				need = m
			if need not in d:
				d[need] = 1
			else:
				d[need] += 1
			M = max(M, need + (d[need] - 1) * k)
		if M != 0:
			M += 1
		print(M)
main()


def keywithmaxval(d):
	v = list(d.values())
	k = list(d.keys())
	sudo = []
	for i in d:
		sudo.append([d[i], i])
	sudo.sort()
	m = max(sudo)[0]
	for j in sudo:
		if j[0] == m:
			return [j[1], m]
for _ in [0] * int(input()):
	(n, x) = map(int, input().split())
	arr = [int(a) for a in input().split()]
	dic = {}
	for i in arr:
		if i % x not in dic:
			dic[i % x] = 1
		else:
			dic[i % x] += 1
	if 0 in dic:
		dic[0] = 0
	(k, m) = keywithmaxval(dic)
	if k != 0:
		print((m - 1) * x + (x - k + 1))
	else:
		print(0)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	ar = [int(i) for i in input().split()]
	for x in range(n):
		ar[x] = ar[x] % k
	ar.sort()
	freq = {}
	check = 0
	for item in ar:
		if item == 0:
			pass
		elif item in freq:
			freq[item] += 1
		else:
			freq[item] = 1
			check += 1
	if check == 0:
		print(0)
	else:
		Keymax = max(freq, key=freq.get)
		print(k * (ar.count(Keymax) - 1) + k - Keymax + 1)


t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	lis = [0] * n
	for j in range(n):
		if arr[j] % k != 0:
			lis[j] = k - arr[j] % k
	lis.sort()
	ans = 0
	a = 1
	for j in range(n):
		if j != 0 and lis[j] != 0:
			if lis[j] == lis[j - 1]:
				ans = max(ans, a * k + lis[j])
				a += 1
			else:
				ans = max(ans, lis[j])
				a = 1
		elif j == 0 and lis[j] != 0:
			ans = max(ans, lis[j])
			a = 1
	if ans == 0:
		print(0)
	else:
		print(ans + 1)


t = int(input())
while t > 0:
	t = t - 1
	(n, k) = map(int, input().split())
	a = input()
	A = list(map(int, list(a.split())))
	d = {}
	for i in range(n):
		y = A[i] % k
		if y in d:
			d[y] = d[y] + 1
		else:
			d[y] = 1
	m = 0
	e = 0
	for i in d:
		if i != 0:
			if m < d[i]:
				m = d[i]
				e = i
			if m == d[i]:
				if i < e:
					e = i
	if e == 0:
		print(0)
	else:
		b = k - e
		c = k - e + (m - 1) * k + 1
		print(c)


import math
import os
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	d = {}
	for i in ar:
		if i % k != 0:
			if k - i % k in d:
				d[k - i % k] += 1
			else:
				d[k - i % k] = 1
	c = 0
	for j in d.keys():
		c = max(c, k * (d[j] - 1) + j + 1)
	print(c)


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = {}
	i = 0
	while i != len(l):
		if l[i] % k == 0:
			i += 1
		else:
			d[k - l[i] % k] = d.get(k - l[i] % k, 0) + 1
			i += 1
	if len(d) == 0:
		print(0)
	else:
		ma = 0
		i = 0
		for (j, m) in d.items():
			if m > ma:
				ma = m
				i = j
			elif m == ma and j > i:
				i = j
		print((ma - 1) * k + i + 1)
	t -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = [int(i) for i in input().split()]
	mod = [k - i % k for i in arr]
	mod = [i for i in mod if i != k]
	from collections import Counter
	c = Counter(mod)
	maxi = 0
	cand = -1
	for i in c:
		if c[i] > maxi:
			maxi = c[i]
			cand = i
		elif c[i] == maxi:
			cand = max(i, cand)
	if cand == -1:
		print(0)
		continue
	minimWithReqX = 1000000000000000
	for x in arr:
		if k - x % k == cand:
			minimWithReqX = min(minimWithReqX, x)
	reqX = minimWithReqX // k * k + k * maxi
	print(max(0, reqX - minimWithReqX + 1))


for t in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	dic = {}
	for i in arr:
		if dic.get(i % k, -1) == -1:
			if i % k == 0:
				dic[i % k] = 0
			else:
				dic[i % k] = i + k - i % k - i
		elif i % k == 0:
			dic[i % k] = 0
		else:
			dic[i % k] = dic[i % k] + k
	max1 = 0
	for i in dic:
		max1 = max(max1, dic[i])
	if max1 != 0:
		max1 += 1
	print(max1)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	dic = {}
	c = 1
	for j in a:
		temp = k - j % k
		if temp == k:
			continue
		if temp in dic:
			dic[temp] += 1
		else:
			dic[temp] = 1
	for j in dic.keys():
		if (dic[j] - 1) * k + j + 1 > c:
			c = (dic[j] - 1) * k + j + 1
	if dic == {}:
		print('0')
	else:
		print(c)


import math as mt

def mot(arr, n):
	Hash = dict()
	for i in range(n):
		if arr[i] in Hash.keys():
			Hash[arr[i]] += 1
		else:
			Hash[arr[i]] = 1
	max_count = 0
	res = -1
	for i in Hash:
		if max_count < Hash[i]:
			res = i
			max_count = Hash[i]
	return res
from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	brr = []
	for i in arr:
		if i % k != 0:
			p = i // k
			p += 1
			p = p * k
			p = p - i
			brr.append(p)
	if len(brr) == 0:
		print('0')
	else:
		brr.sort()
		brr.reverse()
		mx = mot(brr, len(brr))
		ct = brr.count(mx)
		ct -= 1
		k = k * ct
		k = k + mx
		print(k + 1)


from collections import defaultdict
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = defaultdict(int)
	for i in l:
		if i % k != 0:
			d[i % k] += 1
	x = 0
	for i in d:
		v = d[i] * k - i
		x = max(v, x)
	print(x + 1 if x else 0)


n = input('')
n = int(n)
matrix = []
cnt = []
for i in range(n):
	cnt.append(list(map(int, input().split())))
	entries = list(map(int, input().split()))
	matrix.append(entries)
for i in range(n):
	my_cnt = cnt[i]
	mat = matrix[i]
	k = my_cnt[1]
	x = list(map(lambda mat: mat % k, mat))
	y = list(map(lambda x: k - x if x else x, x))
	if sum(y) == 0:
		print(0)
		continue
	ty = sorted(y)
	num0 = ty.count(0)
	if num0 != 0:
		for i in range(num0):
			ty.remove(0)
	freq = ty.copy()
	maxx = 1
	flag = 0
	fin_max = 0
	inc = 1
	for i in range(len(ty)):
		if i == len(ty) - 1:
			break
		if ty[i] == ty[i + 1]:
			if i == len(ty) - 2:
				inc = inc + 1
				maxx = max(inc, maxx)
				if maxx == inc:
					fin_max = ty[i]
				break
			else:
				inc = inc + 1
		else:
			maxx = max(inc, maxx)
			if maxx == inc:
				fin_max = ty[i]
			inc = 1
	if maxx == 1:
		print(max(freq) + 1)
	else:
		print(fin_max + 1 + (maxx - 1) * k)


from collections import defaultdict
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = a[i] % k
	a.sort(reverse=True)
	if a[0] == 0:
		print(0)
		continue
	d = defaultdict(int)
	i = 0
	while i < n and a[i] != 0:
		d[a[i]] += 1
		i += 1
	aset = set(a)
	if 0 in aset:
		aset.remove(0)
	m = max(d.values())
	mn = float('inf')
	for i in aset:
		if d[i] == m and i < mn:
			mn = i
	mov = 1
	mov += (m - 1) * k + (k - mn)
	print(mov)


from sys import stdin, stdout
import bisect

def st():
	return list(stdin.readline())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
			n = n - 1
		else:
			a = a * a
			n = n >> 1
	return r

def solve():
	(n, k) = mp()
	l = li()
	d = {}
	x = []
	for i in l:
		a = i % k
		if a != 0:
			if a not in d:
				d[a] = 1
				x.append(k - a)
			else:
				x.append(k - a + k * d[a])
				d[a] += 1
	if len(x) > 0:
		pr(max(x) + 1)
	else:
		pr(0)
for _ in range(inp()):
	solve()


from collections import Counter
t = int(input())
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	rem = []
	for i in range(n):
		temp = arr[i] % k
		temp = (k - temp) % k
		if temp != 0:
			rem.append(temp)
	if len(rem) == 0:
		print(0)
	else:
		count = Counter(rem)
		x = 0
		for i in range(len(rem)):
			temp = rem[i] + k * (count[rem[i]] - 1)
			if temp > x:
				x = temp
		print(x + 1)


import sys
input = sys.stdin.readline
from collections import defaultdict
t = int(input())
for ii in range(t):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	rem = defaultdict(int)
	ans = [0] * n
	for i in range(len(a)):
		if a[i] % k != 0:
			ans[i] = k - a[i] % k + k * rem[a[i] % k]
			rem[a[i] % k] += 1
	if set(ans) == {0}:
		print(0)
	else:
		print(max(ans) + 1)


import sys
import math
strInp = lambda : input().strip().split()
intInp = lambda : list(map(int, strInp()))
for t in range(int(input())):
	(n, k) = intInp()
	arr = intInp()
	for i in range(n):
		arr[i] = k - arr[i] % k
	mySet = {}
	for i in arr:
		if i == k:
			continue
		if i in mySet:
			mySet[i] += 1
		else:
			mySet[i] = 1
	m = -1
	for key in mySet:
		m = max(m, key + k * (mySet[key] - 1))
	print(m + 1)


import sys
import math
import collections
import heapq
import queue
import itertools
import functools
import operator
import time
readline = sys.stdin.readline
IPS = lambda : readline().rstrip()
IP = lambda : int(readline().rstrip())
MP = lambda : map(int, readline().split())
LS = lambda : list(map(int, readline().split()))

def solve():
	for _ in range(IP()):
		(n, k) = MP()
		arr = LS()
		di = dict()
		for elem in arr:
			if elem % k != 0:
				z = k - elem % k
				if z in di:
					di[z] += 1
				else:
					di[z] = 1
		mx = 0
		for (key, val) in di.items():
			if val == 1:
				if key > mx:
					mx = key
			else:
				temp = key + (val - 1) * k
				if temp > mx:
					mx = temp
		print(mx + 1) if mx > 0 else print(0)
solve()


t = int(input())
while t > 0:
	(n, k) = list(map(int, input().split()))
	nums = list(map(int, input().split()))
	rems = {}
	for x in nums:
		r = x % k
		if r > 0:
			r = k - r
			rems[r] = rems.get(r, 0) + 1
	maxr = 0
	maxi = 0
	rs = sorted(list(rems.keys()))
	for x in rs:
		r = rems[x]
		if r >= maxr:
			maxr = r
			maxi = x
	moves = 0
	if maxr > 0:
		moves = k * maxr - (k - maxi - 1)
	print(moves)
	t = t - 1


from collections import defaultdict
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = [int(a) for a in input().split()]
	cnt = 0
	d = defaultdict(lambda : 0)
	for i in range(n):
		if A[i] % k != 0:
			cnt = max(cnt, k - A[i] % k + d[A[i] % k] * k)
			d[A[i] % k] += 1
	if cnt > 0:
		cnt += 1
	print(cnt)


t = int(input())
while t != 0:
	(n, k) = map(int, input().split())
	arrA = list(map(int, input().split()))
	x = 0
	move = 0
	dictCount = dict()
	for i in range(n):
		remainder = arrA[i] % k
		if remainder == 0:
			continue
		needToAdd = k - remainder
		if needToAdd not in dictCount:
			dictCount[needToAdd] = 0
		dictCount[needToAdd] += 1
	keyNeedToCheck = 0
	for key in dictCount.keys():
		temp = key + k * (dictCount[key] - 1)
		keyNeedToCheck = max(keyNeedToCheck, temp)
	if keyNeedToCheck != 0:
		move = keyNeedToCheck + 1
	print(move)
	t -= 1


def mostFrequent(arr, n):
	arr.sort()
	max_count = 1
	res = arr[0]
	curr_count = 1
	for i in range(1, n):
		if arr[i] == arr[i - 1]:
			curr_count += 1
		else:
			if curr_count >= max_count:
				max_count = curr_count
				res = arr[i - 1]
			curr_count = 1
	if curr_count >= max_count:
		max_count = curr_count
		res = arr[n - 1]
	return res

def f(al, k):
	ll = []
	for i in al:
		tp = k - i % k
		if tp == k:
			tp = 0
		if tp != 0:
			ll.append(tp)
	if len(ll) == 0:
		return 0
	res = mostFrequent(ll, len(ll))
	ct = 0
	for i in ll:
		if i == res:
			ct = ct + 1
	return (ct - 1) * k + res + 1
for tc in range(int(input())):
	al = list(map(int, input().split()))
	k = al[1]
	al = list(map(int, input().split()))
	print(f(al, k))


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


R = lambda : map(int, input().split())
(t,) = R()
for i in range(t):
	(n, k) = R()
	a = [i % k for i in R()]
	a.sort()
	m = 1
	nu = a[0]
	n = 1
	for j in range(len(a) - 1):
		if a[j] == 0:
			nu = a[j + 1]
			continue
		if a[j] == a[j + 1]:
			n += 1
		else:
			n = 1
		if n > m:
			m = n
			nu = a[j]
	if nu == 0:
		print(0)
	else:
		print(k - nu + 1 + (m - 1) * k)


from collections import defaultdict
T = int(input())
for t in range(T):
	(n, k) = [int(i) for i in input().split()]
	A = [(k - int(i)) % k for i in input().split()]
	d = defaultdict(int)
	for i in A:
		d[i] += 1
	cur_max = 0
	for i in d:
		if i != 0:
			cur_max = max(cur_max, d[i])
	if cur_max == 0:
		print(0)
		continue
	max_ind = max([i for i in d if d[i] == cur_max])
	print((cur_max - 1) * k + max_ind + 1)


import sys
import math
input = sys.stdin.readline
t = int(input())
for t1 in range(t):
	(n, k) = list(map(int, input().split(' ')))
	l = list(map(int, input().split(' ')))
	a = []
	for i in range(n):
		rem = l[i] % k
		if rem != 0:
			extra = k - rem
			a.append(extra)
	a.sort()
	d = {}
	m = 0
	for i in range(len(a)):
		if d.get(a[i], 0) == 0:
			d[a[i]] = 1
		else:
			a[i] = m
			while d.get(a[i], 0) != 0:
				a[i] = a[i] + k
			d[a[i]] = 1
		m = a[i]
	if len(a) > 0:
		print(max(a) + 1)
	else:
		print(0)


for i in range(int(input())):
	(n, k) = input().split(' ')
	(n, k) = (int(n), int(k))
	A = input().split(' ')
	for j in range(n):
		A[j] = int(A[j]) % k
	A.sort()
	ma = 1
	rema = A[0]
	tem = 1
	for j in range(1, n):
		if A[j] == 0:
			continue
		if A[j] == A[j - 1]:
			tem += 1
			if tem > ma:
				ma = tem
				rema = A[j]
		elif A[j - 1] == 0:
			tem = 1
			rema = A[j]
		else:
			tem = 1
	if rema == 0:
		print(0)
	else:
		print(ma * k - rema + 1)


from sys import stdin, stdout
import math, queue, heapq
fastinput = stdin.readline
fastout = stdout.write
t = int(fastinput())
while t:
	t -= 1
	(n, k) = map(int, fastinput().split())
	b = []
	for i in input().strip().split(' '):
		b.append(int(i) % k)
	b.sort(reverse=True)
	count = 0
	last = k + 1
	ans = 0
	for i in b:
		if i == 0:
			break
		elif i == last:
			count += 1
		else:
			ans = max(ans, (count - 1) * k + (k - last) + 1, k - last + 1)
			last = i
			count = 1
	ans = max(ans, (count - 1) * k + (k - last) + 1, k - last + 1)
	print(ans)


from collections import Counter
for _ in range(int(input())):
	(N, K) = list(map(int, input().split()))
	arr = Counter(map(lambda x: int(x) % K, input().split()))
	mx = 0
	for i in arr:
		r = K - i
		if r == K:
			continue
		mx = max(mx, r + K * (arr[i] - 1))
	print(mx + 1 if mx else 0)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	moves = 0
	x = 0
	for i in range(n):
		if a[i] % k == 0:
			a[i] = 0
		else:
			a[i] = k - a[i] % k
	a.sort()
	max_score = 0
	max_number = 0
	now_score = 0
	now_number = 0
	for i in range(n):
		if a[i] == 0:
			continue
		if a[i] == now_number:
			now_score += 1
		else:
			if now_score >= max_score:
				max_score = now_score
				max_number = now_number
			now_number = a[i]
			now_score = 1
	if now_score >= max_score:
		max_score = now_score
		max_number = now_number
	if max_number == 0:
		print(0)
	else:
		print((max_score - 1) * k + max_number + 1)


from collections import defaultdict
t = int(input())
for test in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	store = defaultdict(int)
	mx = 0
	for i in a:
		if i % k != 0:
			store[k - i % k] += 1
			mx = max(mx, store[k - i % k])
	mx_key = 0
	for i in store:
		if store[i] == mx:
			if i > mx_key:
				mx_key = i
	print(max(k * (mx - 1) + mx_key + 1, 0))


def compute(n, k, arr):
	cnt = 0
	cur = k
	for i in range(n):
		arr[i] = arr[i] % k
	arr.sort()
	for i in range(n):
		if arr[i] % k != 0:
			temp = k - arr[i] % k
			if i > 0 and arr[i - 1] == arr[i]:
				cnt = max(temp + cur + 1, cnt)
				cur += k
			else:
				cur = k
				cnt = max(temp + 1, cnt)
	return cnt
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(compute(n, k, arr))


from collections import Counter
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	b = list(map(lambda x: k - int(x) % k, input().split()))
	c = Counter(b)
	del c[k]
	if not c:
		print(0)
		continue
	mostcom_n = 0
	mostcom_el = 0
	for el in c:
		if c[el] >= mostcom_n:
			if mostcom_el == 0:
				mostcom_el = el
			if c[el] == mostcom_n:
				if el > mostcom_el:
					mostcom_el = el
			if c[el] > mostcom_n:
				mostcom_el = el
			mostcom_n = c[el]
	print((mostcom_n - 1) * k + mostcom_el + 1)


import math
from sys import stdin
from collections import Counter
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	s = set()
	m = 0
	l = []
	for i in range(n):
		if a[i] % k == 0:
			continue
		rem = k - a[i] % k
		l.append(rem)
	d = Counter(l)
	for i in d:
		m = max(m, i + (d[i] - 1) * k)
	if m != 0:
		m = m + 1
	print(m)


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


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import sys
from collections import Counter

def solve(n, k, A):
	M = [-a % k for a in A]
	C = Counter(M)
	if C[0] == n:
		return 0
	cnt = 0
	v = 0
	for (key, val) in C.items():
		if key == 0:
			continue
		if val == cnt:
			cnt = val
			v = max(v, key)
		elif val > cnt:
			cnt = val
			v = key
	return k * (cnt - 1) + v + 1

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		A = tuple(map(int, input().split()))
		ans = solve(n, k, A)
		sys.stdout.write(str(ans) + '\n')
main()


import math
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
for _ in range(I()):
	(n, m) = M()
	a = LI()
	d = defaultdict(int)
	for i in range(n):
		if a[i] % m != 0:
			d[m - a[i] % m] += 1
	ans = 0
	for i in d.keys():
		ans = max(ans, i + (d[i] - 1) * m + 1)
	print(ans)


from math import *
from collections import *
from bisect import *
import sys
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	for i in a:
		if i % k != 0:
			try:
				d[k - i % k] += 1
			except:
				d[k - i % k] = 1
	try:
		x = max(d.values())
	except:
		print(0)
		continue
	r = -1
	for i in d.keys():
		if d[i] == x:
			r = max(r, i)
	print((x - 1) * k + r + 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {k - 1: 0}
	for i in a:
		if i % k:
			if k - i % k not in d:
				d[k - i % k] = 0
			d[k - i % k] += 1
	m = max(d, key=lambda x: (d[x], x))
	print(k * (d[m] - 1) + m + 1)


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	ds = {}
	for j in range(n):
		e = a[j]
		if e % k != 0:
			ele = k - e % k
			if ele not in ds.keys():
				ds[ele] = 1
			else:
				ds[ele] += 1
	mi = -1
	mv = -1
	for j in ds.keys():
		if ds[j] > mv or (ds[j] == mv and mi < j):
			mi = j
			mv = ds[j]
	if mi == -1:
		print(0)
	else:
		print((mv - 1) * k + mi + 1)


from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
import math
rl = lambda : stdin.readline()
rll = lambda : stdin.readline().split()
rli = lambda : map(int, stdin.readline().split())
rlf = lambda : map(float, stdin.readline().split())
(INF, NINF) = (float('inf'), float('-inf'))

def main():

	def dist(a, k):
		(q, r) = divmod(a, k)
		return k - r if r > 0 else 0
	T = int(rl())
	for _ in range(T):
		moves = 0
		(n, k) = rli()
		A = list(rli())
		layers = defaultdict(lambda : deque())
		for a in A:
			layers[dist(a, k)].append(a)
		last = 0
		ans = 0
		for d in layers.keys():
			if d == 0:
				continue
			x = d + 1 + (len(layers[d]) - 1) * k
			ans = max(ans, x)
		print(ans)
	stdout.close()
main()


from collections import defaultdict as ddict
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	lis = list(map(int, input().split()))
	d = ddict(int)
	ans = 0
	for i in range(n):
		if lis[i] % k == 0:
			continue
		m = lis[i] // k + 1
		rem = int(m * k - lis[i])
		d[rem] += 1
		val = rem + (d[rem] - 1) * k
		ans = max(ans, val)
	if ans == 0:
		print(0)
	else:
		print(ans + 1)


from collections import OrderedDict

def solve():
	(n, k) = (int(i) for i in input().split(' '))
	arr = {}
	for i in input().split(' '):
		mod = int(i) % k
		if mod == 0:
			continue
		if k - mod not in arr:
			arr[k - mod] = 1
		else:
			arr[k - mod] += 1
	x = 0
	arr = OrderedDict(sorted(arr.items()))
	while len(arr) > 0:
		prev_key = 0
		for (key, val) in arr.items():
			x += key - prev_key
			arr[key] -= 1
			prev_key = key
		arr = {key: val for (key, val) in arr.items() if val > 0}
		if len(arr) > 0:
			x += k - prev_key
	print(x if x == 0 else x + 1)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	(n, k) = [int(t) for t in input().split()]
	numbers = [int(t) for t in input().split()]
	remainders = {}
	for num in numbers:
		if num % k == 0:
			continue
		if k - num % k not in remainders:
			remainders[k - num % k] = 0
		remainders[k - num % k] += 1
	maxvalue = 0
	maxkey = 0
	for key in remainders:
		if remainders[key] == maxvalue:
			maxkey = max(key, maxkey)
		elif remainders[key] > maxvalue:
			maxkey = key
			maxvalue = remainders[key]
	result = (maxvalue - 1) * k + maxkey + 1
	if maxvalue == 0:
		result = 0
	print(result)


from collections import defaultdict
t = int(input())
for a0 in range(0, t):
	(n, k) = list(map(int, input().split(' ')))
	a = list(map(int, input().split(' ')))
	d = defaultdict(int)
	val = -1
	indx = -1
	for i in a:
		r = 0
		if i % k != 0:
			r = k - i % k
		if r == 0:
			continue
		d[r] += 1
		if d[r] > val:
			val = d[r]
			indx = r
		elif d[r] == val:
			indx = max(indx, r)
	print(max(0, val - 1) * k + (indx + 1))


import collections
t = int(input())
for _ in range(t):
	cache = set()
	(n, k) = map(int, input().split())
	List = list(map(int, input().split()))
	prev = {}
	for each in List:
		if each % k != 0:
			req = k - each % k
			if req not in cache:
				cache.add(req)
				prev[req] = req
			else:
				cache.add(prev[req] + k)
				prev[req] += k
	if cache:
		print(max(cache) + 1)
	else:
		print(0)


def main():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = {}
	for i in range(len(a)):
		if a[i] % k != 0:
			if b.get(k - a[i] % k) == None:
				b[k - a[i] % k] = 1
			else:
				b[k - a[i] % k] += 1
	mx = 0
	index = -1
	for key in b:
		if b[key] >= mx:
			if mx != b[key] or key > index:
				mx = b[key]
				index = key
	if index == -1:
		print(0)
		return
	print(index + (mx - 1) * k + 1)
	return

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


from collections import Counter
from math import ceil
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a = Counter([k * ceil(i / k) - i for i in a])
	not_available = set()
	for el in sorted(a):
		foo = el
		for cnt in range(a[el]):
			if foo != 0:
				while True:
					if foo not in not_available:
						not_available.add(foo)
						break
					else:
						foo += k
	if len(not_available) != 0:
		print(max(not_available) + 1)
	else:
		print(0)


for i in range(int(input())):
	lis = []
	(n, x) = [int(k) for k in input().split()]
	arr = list(map(int, input().split()))
	for ele in arr:
		ele = x - ele % x
		lis.append(ele)
	lis.sort()
	f = lis[0]
	ma = 0
	maxx = 0
	g = -1
	for i in range(n):
		if lis[i] != x and lis[i] == f:
			ma += 1
		else:
			ma = 1
			f = lis[i]
		if ma >= maxx:
			maxx = ma
			if lis[i] != x:
				g = lis[i]
	print(x * (maxx - 1) + (g + 1))


from collections import Counter
t = int(input())
for _ in range(0, t):
	(n, k) = map(int, input().split())
	aa = [int(i) % k for i in input().split()]
	change = [k - int(i) for i in aa if i]
	c = Counter(change)
	ans = 0
	for i in c:
		ans = max(ans, i + k * (c[i] - 1))
	if ans == 0:
		print(ans)
	else:
		print(ans + 1)


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	(n, k) = value()
	a = array()
	freq = defaultdict(int)
	for i in a:
		if i % k == 0:
			continue
		else:
			x = (i // k + 1) * k - i
		freq[x] += 1
	if len(freq) == 0:
		print(0)
		continue
	till = max(freq.keys())
	for i in freq:
		if freq[i] > 1:
			till = max(i + k * (freq[i] - 1), till)
	print(till + 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	for i in range(n):
		r = a[i] % k
		if r != 0:
			if r in d:
				d[r].append(d[r][-1] + k)
			else:
				d[r] = [k - r]
	x = 0
	for i in d:
		x = max(max(d[i]), x)
	if d:
		print(x + 1)
	else:
		print(0)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	b = 0
	for i in a:
		c = k - i % k
		if c < k:
			if c in d:
				d[c] += 1
			else:
				d[c] = 1
	for i in d:
		b = max(b, (d[i] - 1) * k + i + 1)
	print(b)


from collections import defaultdict
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	di = defaultdict(int)
	for i in arr:
		di[k - i % k] += 1
	ls = []
	for (i, j) in di.items():
		if i != k:
			ls.append([i, j])
	if ls == []:
		print(0)
	else:
		ls = sorted(ls, key=lambda x: (-x[1], -x[0]))
		ans = (ls[0][1] - 1) * k + ls[0][0] + 1
		print(ans)


import bisect
import os
import gc
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque
import heapq
import math
import statistics

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007

def readTree(n, m):
	adj = [deque([]) for _ in range(n + 1)]
	for _ in range(m):
		(u, v) = ain()
		adj[u].append(v)
		adj[v].append(u)
	return adj

def main():
	for _ in range(iin()):
		(n, k) = ain()
		l = ain()
		d = {}
		count = 0
		for i in l:
			if i % k != 0:
				if k - i % k not in d:
					d[k - i % k] = 1
				else:
					d[k - i % k] += 1
				count += 1
		maxi = 0
		ki = 0
		for (key, value) in d.items():
			if maxi < value:
				maxi = value
				ki = key
			elif maxi == value:
				ki = max(ki, key)
		if maxi == 0:
			print(0)
		else:
			print(ki - 0 + 1 + k * (maxi - 1))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


cases = input()
for i in range(int(cases)):
	inputNum1 = input()
	inputNum2 = inputNum1.split(' ')
	jmlAngka = int(inputNum2[0])
	modulo = int(inputNum2[1])
	inputDeretAngka = input()
	dictMod = dict()
	maxCount = 0
	maxNum = 0
	for i in inputDeretAngka.split(' '):
		idx = 0
		if int(i) % modulo > 0:
			idx = modulo - int(i) % modulo
			if idx in dictMod:
				dictMod[idx] += 1
			else:
				dictMod[idx] = 1
			if maxCount < dictMod[idx]:
				maxCount = dictMod[idx]
				maxNum = idx
			elif maxCount == dictMod[idx]:
				if maxNum < idx:
					maxNum = idx
	if maxNum == 0:
		print('0')
	else:
		print(modulo * (maxCount - 1) + maxNum + 1)


from collections import Counter
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(lambda x: int(x) % k, input().split()))
	residues = sorted([residue_data for residue_data in Counter(a).items()], key=lambda x: x[0])
	max_count = 0
	max_residue = 0
	for element in residues:
		(residue, count) = element
		if residue != 0:
			if count > max_count:
				(max_count, max_residue) = (count, residue)
	if max_residue == 0:
		print(0)
	else:
		print(k * max_count - max_residue + 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] %= k
		a[i] = (k - a[i]) % k
	a.sort()
	j = 0
	cnt = 1
	while j < n:
		if a[j] != 0:
			break
		j += 1
	b = []
	i = j + 1
	while i < n:
		cnt = 1
		i = j + 1
		if i >= n or j >= n:
			break
		while a[i] == a[j]:
			a[i] += cnt * k
			cnt += 1
			i += 1
			if i == n:
				break
		j = i
	a.sort()
	if a[-1] == 0:
		print('0')
	else:
		print(a[-1] + 1)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = set()
	mxi = {}
	arr = map(int, input().split())
	for x in arr:
		m = x % k
		if m != 0:
			m2 = k - m
			if m not in mxi.keys():
				mxi[m] = m2
			else:
				m2 = mxi[m] + k
				mxi[m] += k
			s.add(m2)
	ans = 0
	flist = list(s)
	list.sort(flist)
	if len(flist) != 0:
		ans = flist[-1] + 1
	print(ans)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	m = {}
	(max_mod, max_i) = (-1, -1)
	a = list(map(int, input().split()))
	for i in range(n):
		x = a[i]
		if x % k not in m:
			m[x % k] = 0
		m[x % k] += 1
		if x % k == 0:
			continue
		if m[x % k] > max_mod or (m[x % k] == max_mod and x % k < max_i):
			max_mod = m[x % k]
			max_i = x % k
	if max_mod == -1:
		print(0)
	else:
		print((max_mod - 1) * k + (k - max_i) + 1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush
from math import ceil

def main():
	for _ in range(N()):
		(n, k) = RL()
		arr = RLL()
		arr = [ceil(i / k) * k - i if i > k else k - i for i in arr if i % k != 0]
		ct = [[i, j] for (i, j) in Counter(arr).items()]
		ct.sort()
		ma = 0
		bs = 0
		for i in range(len(ct)):
			(now, num) = ct[i]
			ma = max(ma, now + k * (num - 1))
		if not arr:
			print(0)
		else:
			print(ma + 1)
main()


from itertools import groupby
for _ in range(int(input())):
	(n, k) = [int(_) for _ in input().split()]
	a = [int(_) for _ in input().split()]
	rems = sorted((_ % k for _ in a), key=lambda x: -x)
	rems = [[k, len(list(v))] for (k, v) in groupby(rems)]
	x = 0
	done = 0
	i = 0
	while done != n:
		j = i % len(rems)
		if rems[j][1] == 0:
			i += 1
			continue
		if rems[j][0] % k == 0:
			done += rems[j][1]
			rems[j][1] = 0
			i += 1
			continue
		x += (k - (x + rems[j][0]) % k) % k + 1
		rems[j][1] -= 1
		done += 1
		i += 1
	print(x)


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


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list((int(num) % k for num in input().split()))
	dicti = {}
	for z in range(0, len(a)):
		if a[z] != 0:
			if a[z] in dicti:
				dicti[a[z]] += 1
			else:
				dicti[a[z]] = 1
	if dicti:
		maxi = max(dicti.values())
		l = [k for (k, v) in dicti.items() if v == maxi]
		print(maxi * k - min(l) + 1)
	else:
		print('0')


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
import collections
import math
import heapq
import re

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def most_frequent(list):
	return max(set(list), key=list.count)

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	for _ in range(inin()):
		(n, k) = map(int, input().split())
		a = ain()
		count = 0
		x = 0
		arr = []
		for i in range(n):
			temp = a[i] % k
			if temp != 0:
				arr.append(k - temp)
		if len(arr) == 0:
			print(0)
			continue
		else:
			z = Counter(arr)
			for (key, values) in z.items():
				if key + 1 > x:
					x = key + 1
				if key + 1 + (values - 1) * k > x:
					x = key + (values - 1) * k + 1
		print(x)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	rem = [i % k for i in a if i % k != 0]
	count = Counter(rem)
	maxx = -1
	l = list(count.keys())
	for i in range(len(l)):
		num = k - l[i] + (count[l[i]] - 1) * k
		if num > maxx:
			maxx = num
	print(maxx + 1)


from collections import defaultdict
import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(II()):
		(n, k) = MI()
		aa = LI()
		if k == 1:
			print(0)
			continue
		cnt = defaultdict(int)
		for a in aa:
			cnt[a % k] += 1
		mx = 0
		mxi = 0
		for (i, c) in sorted(cnt.items()):
			if i == 0:
				continue
			if c > mx:
				mx = c
				mxi = i
		if mx == 0:
			ans = 0
		else:
			ans = k * mx + 1 - mxi
		print(ans)
main()


for _ in range(int(input())):
	mydict = dict()
	(x, k) = map(int, input().split())
	mylist = list(map(int, input().split()))
	for i in range(x):
		if mylist[i] % k != 0:
			temp = abs(mylist[i] % k - k)
			if temp in mydict:
				mydict[temp + k * mydict[temp]] = 1
				mydict[temp] += 1
			else:
				mydict[temp] = 1
	print(0 if len(mydict) == 0 else max(mydict.keys()) + 1)


from collections import *
F = lambda : map(int, input().split())
(v,) = F()
for _ in [0] * v:
	(s, b) = F()
	f = Counter((x % b for x in F()))
	print(max((x and 1 - x + b * f[x] for x in f)))


def next():
	return [int(x) for x in input().split()]
(ca,) = next()
for _ in range(ca):
	(n, k) = next()
	x = next()
	x = sorted([i % k for i in x])
	r = 0
	i = 0
	while i < len(x):
		j = i
		while j < len(x) and x[i] == x[j]:
			j += 1
		if x[i] != 0:
			r = max(r, (j - i) * k - x[i] + 1)
		i = j
	print(r)


from sys import stdin, stdout
from bisect import bisect, bisect_left, bisect_right

def gt():
	return map(int, stdin.readline().split())

def gi():
	return int(stdin.readline())

def gl():
	return list(map(int, stdin.readline().split()))

def gs():
	return stdin.readline()
t = gi()
for _ in range(t):
	d = dict()
	(n, k) = gt()
	a = gt()
	for i in a:
		temp = i % k
		if temp:
			if d.get(k - temp, None) == None:
				d[k - temp] = 0
			d[k - temp] += 1
	ans = 0
	for (keys, v) in d.items():
		ans = max(ans, (v - 1) * k + keys)
	if ans != 0:
		ans += 1
	print(ans)


from collections import defaultdict
it = lambda : list(map(int, input().strip().split()))

def solve():
	(n, k) = it()
	A = it()
	m = defaultdict(int)
	ans = 0
	for i in range(n):
		r = k - A[i] % k
		if r == k:
			continue
		ans = max(ans, m[r] * k + r + 1)
		m[r] += 1
	print(ans)
T = int(input())
for _ in range(T):
	solve()


for t in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	for i in range(n):
		arr[i] = (k - arr[i] % k) % k
	arr.sort()
	i = 0
	while i < n:
		if arr[i] > 0:
			j = i + 1
			while j < n and arr[i] == arr[j]:
				arr[j] = arr[i] + (j - i) * k
				j += 1
			i = j
		else:
			i += 1
	if max(arr) == 0:
		print(0)
	else:
		print(max(arr) + 1)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	(n, k) = sp()
	arr = l()
	c = dd(int)
	for i in arr:
		c[i % k] += 1
	c = sorted(c.items(), key=lambda temp: temp[0], reverse=True)
	x = 0
	for i in range(len(c)):
		c[i] = list(c[i])
	while True:
		r = True
		for i in range(len(c)):
			if not c[i][1] or c[i][0] == 0:
				continue
			if c[i][1] > 0:
				r = False
			c[i][1] -= 1
			temp = k - (c[i][0] + x) % k
			x += temp % k
			x += 1
		if r:
			break
	out(x)


from collections import defaultdict

def solve(n, k, a):
	d = defaultdict(int)
	m = 0
	mi = 0
	cnt = 0
	for v in a:
		if v % k != 0:
			cnt += 1
			r = k - v % k
			d[r] += 1
			vv = d[r]
			if vv > m:
				m = vv
				mi = r
			elif vv == m and r > mi:
				mi = r
	if cnt == 0:
		return 0
	return k * (m - 1) + mi + 1
t = int(input())
for i_t in range(t):
	current_str = input().split(' ')
	n = int(current_str[0])
	k = int(current_str[1])
	a = list(map(int, input().split(' ')))
	print(solve(n, k, a))


import sys
from collections import defaultdict

def get_int():
	return int(sys.stdin.readline().strip())

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def out(data):
	return sys.stdout.write(str(data))

def out_list(arr):
	return sys.stdout.write(' '.join((str(e) for e in arr)))
MAX = 10 ** 9
MOD = 10 ** 9 + 7
t = get_int()
for _ in range(int(t)):
	(n, k) = get_ints()
	arr = get_list()
	r = defaultdict(lambda : -1)
	r[0] = -1
	for x in arr:
		if x % k:
			if r[x % k] != -1:
				r[x % k] += k
			else:
				r[x % k] = k - x % k
	out(max(r.values()) + 1)
	out('\n')


from sys import stdin, stdout
input = stdin.readline
print = stdout.write
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	b = 0
	for i in a:
		c = k - i % k
		if c < k:
			if c in d:
				d[c] += 1
			else:
				d[c] = 1
	for i in d:
		b = max(b, (d[i] - 1) * k + i + 1)
	print(str(b) + '\n')


from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	li = []
	for i in range(len(ar)):
		if ar[i] % k != 0:
			li.append(ar[i])
	if li:
		for i in range(len(li)):
			li[i] = k - li[i] % k
		d = Counter(li)
		while len(set(list(d.values()))) > 1 or max(d.values()) > 0:
			for i in d.copy():
				if d[i] > 0:
					d[i] -= 1
				if d[i] > 0:
					newkey = i + k
					d[newkey] = d[i]
					del d[i]
					newkey = 0
		print(max(d.keys()) + 1)
	else:
		print(0)


t = int(input())
for tc in range(t):
	(n, k) = map(int, input().split())
	x = 0
	arr = [int(z) for z in input().split()]
	needed = []
	cnt = 0
	usages = {}
	for i in range(n):
		elem = arr[i]
		if elem % k == 0:
			d = 0
			continue
		else:
			d = k - elem % k
		if not usages.get(d):
			usages[d] = 1
		else:
			usages[d] += 1
	found = False
	for (i, j) in sorted(usages.items()):
		cnt = max(cnt, j)
	res = 0
	for (i, j) in sorted(usages.items()):
		if j == cnt:
			res = k * (j - 1) + i
			found = True
	if not found:
		print(0)
		continue
	print(res + 1)


for ii in range(int(input())):
	(n, k) = map(int, input().split())
	s = [int(i) for i in input().split()]
	e = {}
	d = 0
	for i in s:
		x = i % k
		if x == 0:
			continue
		if x not in e:
			e[x] = 1
		else:
			e[x] += 1
	for i in e:
		x = k * (e[i] - 1) + k - i
		d = max(d, x + 1)
	print(d)


from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = {}
	d[0] = 0
	for i in l:
		x = (k - i) % k
		if x:
			if x not in d:
				d[x] = x + 1
			else:
				d[x] += k
	print(max(d.values()))


from typing import Counter
t = int(input())

def solve():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	brr = []
	for i in range(n):
		x = arr[i] % k
		if x != 0:
			brr += [k - x]
	if brr == []:
		print(0)
		return
	hash_map = Counter(brr)
	ans = 0
	for n in hash_map.keys():
		ans = max(ans, n + k * (hash_map[n] - 1))
	print(ans + 1)
while t:
	solve()
	t -= 1


from collections import Counter
T = int(input().strip())
for t in range(T):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().strip().split()))[:n]
	rems = Counter([j % k for j in a if j % k != 0])
	mr = max(rems.values(), default=0)
	mm = min([r - 1 for (r, v) in rems.items() if v == mr], default=0)
	print((mr - 1) * k + (k - mm))


def list_input():
	return list(map(int, input().split()))

def multiple_input():
	return map(int, input().split())
for _ in range(int(input())):
	(n, k) = multiple_input()
	a = list_input()
	rem = {}
	for i in a:
		reminder = i % k
		if reminder == 0:
			reminder = k
		if k - reminder in rem:
			rem[k - reminder] += 1
		else:
			rem[k - reminder] = 1
	ans = []
	for i in rem:
		if i != 0:
			val = i
			val += (rem[i] - 1) * k
			ans.append(val)
	if len(ans) == 0:
		print(0)
	else:
		print(max(ans) + 1)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	B = []
	for i in A:
		B.append((k - i % k) % k)
	B.sort()
	i = 1
	while i < n:
		j = i
		if B[i] != 0 and B[i] == B[i - 1]:
			while j < n:
				if B[j] == B[i - 1]:
					B[j] = B[j] + (j - i + 1) * k
				else:
					break
				j = j + 1
		i = j + 1
	B.sort()
	(c, x) = (0, 0)
	for i in range(n):
		iv = B[i]
		if iv == 0:
			continue
		else:
			c = c + iv - x + 1
			x = iv + 1
	print(c)


for T in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	dictionary = {}
	for i in range(n):
		rem = k - arr[i] % k
		if rem == k:
			rem = 0
		if rem in dictionary.keys():
			dictionary[rem] += 1
		else:
			dictionary[rem] = 1
	maxima = 0
	for (key, values) in dictionary.items():
		if key != 0:
			m = (values - 1) * k + (key + 1)
			if m > maxima:
				maxima = m
	print(maxima)


import sys
from collections import defaultdict
inp = [int(x) for x in sys.stdin.read().split()]
ii = 0
ttt = inp[ii]
ii += 1
for _ in range(ttt):
	(n, k) = inp[ii:ii + 2]
	ii += 2
	r = defaultdict(lambda : -1)
	r[0] = -1
	for x in inp[ii:ii + n]:
		if x % k:
			if r[x % k] != -1:
				r[x % k] += k
			else:
				r[x % k] = k - x % k
	print(max(r.values()) + 1)
	ii += n


for testcase in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if k == 1:
		print(0)
		continue
	if n == 1:
		print((k - a[0] % k) % k + 1)
		continue
	a = filter(lambda i: i != 0, sorted(list(((k - i % k) % k for i in a)), reverse=True))
	(v, id) = (0, -1)
	prev = -1
	cnt = 0
	for i in a:
		if i == prev:
			cnt += 1
		else:
			(v, id) = max((v, id), (cnt, prev))
			cnt = 1
			prev = i
	(v, id) = max((v, id), (cnt, prev))
	if id == -1:
		print(0)
	else:
		print((v - 1) * k + id + 1)


for i in range(int(input())):
	(n, k) = map(int, input().strip().split())
	a = list(map(int, input().strip().split()))
	d = dict.fromkeys(list(map(lambda x: k - x % k, a)), 0)
	for i in a:
		d[k - i % k] += 1
	ans = 0
	for i in d:
		if i % k != 0:
			ans = max(i + 1 + (d[i] - 1) * k, ans)
	print(ans)


from collections import defaultdict
t = int(input())
for _ in range(t):
	(_, k) = map(int, input().split())
	ak = sorted(filter(None, map(lambda x: int(x) % k, input().split())))
	d = defaultdict(int)
	for a in ak:
		d[a] += 1
	maxv = 0
	maxk = 1000000000 + 1
	for (key, v) in d.items():
		if v > maxv or (v == maxv and k < maxk):
			maxv = v
			maxk = key
	if not d:
		print(maxv * k)
	else:
		print(maxv * k - maxk + 1)


from collections import defaultdict as dd
from collections import Counter
from math import log

def solve():
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	rem = []
	for i in a:
		if i % k != 0:
			rem.append(k - i % k)
	if len(rem) == 0:
		print(0)
		return
	c = Counter(rem)
	op = []
	for i in c.keys():
		op.append(k * (c[i] - 1) + i)
	print(max(op) + 1)
t = 1
t = int(input())
for _ in range(t):
	solve()


m = int(input())
while m:
	m -= 1
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	d = {}
	for i in l:
		if i % b != 0:
			d.setdefault(b - i % b, 0)
			d[b - i % b] += 1
	ma = 0
	for (i, j) in d.items():
		ma = max(i + (j - 1) * b, ma)
	if ma == 0:
		print(0)
	else:
		print(ma + 1)


t = int(input())
import math
delay = []
for _ in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	div = {}
	arr = input().split()
	arr = [int(a) for a in arr]
	for i in range(n):
		resid = (k - arr[i] % k + k) % k
		if resid != 0:
			if resid not in div:
				div[resid] = 1
			else:
				div[resid] += 1
	wk = -1
	wv = -1
	for kk in div:
		vv = div[kk]
		if vv > wv or (vv == wv and kk > wk):
			wv = vv
			wk = kk
	ans = (wv - 1) * k + wk + 1
	print(max(0, ans))


import time, math, bisect, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IO():
	return stdin.readline()

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x))

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count

def readTree(v, e):
	adj = [set() for i in range(v + 1)]
	for i in range(e):
		(u1, u2, w) = IP()
		adj[u1].add((u2, w))
		adj[u2].add((u1, w))
	return adj

def dfshelper(adj, i, visited):
	nodes = 1
	visited[i] = True
	for ele in adj[i]:
		if visited[ele] == False:
			nd = dfshelper(adj, ele, visited)
			nodes += nd
	return nodes

def dfs(adj, v):
	visited = [False] * (v + 1)
	li = []
	for i in range(v):
		if visited[i] == False:
			nodes = dfshelper(adj, i, visited)
			li.append(nodes)
	return li
mx = 10 ** 9 + 7

def solve():
	(n, k) = IP()
	a = L()
	cnt = 0
	a.sort()
	d = {}
	cnt = 0
	for ele in a:
		if ele % k == 0:
			cnt += 1
		else:
			inc = (ele // k + 1) * k - ele
			d[inc] = d.get(inc, 0) + 1
	if cnt == n:
		print(0)
		return
	mx = -sys.maxsize
	for ele in d:
		if d[ele] > 1:
			inc = ele + (d[ele] - 1) * k
			mx = max(inc, mx)
		else:
			mx = max(ele, mx)
	print(mx + 1)
t = int(input())
for i in range(t):
	solve()


T = int(input())
for test in range(T):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	dct = {}
	for el in l:
		try:
			dct[el % k] += 1
		except KeyError:
			if el % k != 0:
				dct[el % k] = 1
	try:
		max_el = max(dct.values())
		max_key = 1000000001
		for el in dct.keys():
			if dct[el] == max_el:
				max_key = min(max_key, el)
		print((max_el - 1) * k + (k - max_key) + 1)
	except ValueError:
		print(0)


t = int(input())
while t:
	(n, k) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	s = {}
	for i in arr:
		if i % k:
			temp = k - i % k
		else:
			temp = i % k
		if temp in s:
			s[temp] += 1
		else:
			s[temp] = 1
	max_count = 0
	for (x, v) in s.items():
		if x:
			count = k * (v - 1) + x
			if max_count < count:
				max_count = count
	if max_count:
		print(max_count + 1)
	else:
		print(max_count)
	t -= 1


from collections import defaultdict
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	freq = defaultdict(int)
	f = 0
	for i in arr:
		if i % k != 0:
			f = 1
			d = i // k
			d += 1
			d = d * k
			freq[d - i] += 1
	ans = 0
	for i in freq:
		m = i + (freq[i] - 1) * k
		ans = max(ans, m)
	if f == 1:
		print(ans + 1)
	else:
		print(0)


import math
from collections import *
import sys
from functools import reduce

def get_ints():
	return map(int, input().strip().split())

def get_list():
	return list(get_ints())

def getlistofstring():
	return list(input().strip().split())

def printxsp(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
UGLYMOD = int(1000000000.0) + 7
SEXYMOD = 998244353
MAXN = int(100000.0)
for _testcases_ in range(int(input())):
	(n, k) = get_ints()
	d = Counter(list(map(lambda x: (k - x % k) % k, get_list())))
	se = set()
	if d[0] == n:
		print(0)
	else:
		for (key, val) in d.items():
			if key == 0:
				continue
			indices = val
			for abc in range(indices):
				while key in se:
					key += k
				se.add(key)
		print(max(se) + 1)


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


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	B = {}
	for j in A:
		if j % k not in B:
			B[j % k] = 0
		B[j % k] += 1
	max = 0
	c = k + 1
	for j in B:
		if j != 0 and (B[j] == max and j < c or B[j] > max):
			max = B[j]
			c = j
	if c == k + 1:
		print(0)
	else:
		print(max * k - c + 1)


a = int(input())
for i in range(a):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().strip().split()))
	arr1 = {}
	m = 0
	a
	for j in range(len(arr)):
		l = (k - arr[j]) % k
		if l in arr1:
			arr1[l] += 1
		else:
			arr1[l] = 1
	d = 0
	del arr
	for j in arr1:
		if j != 0:
			d = max(d, 1 + (arr1[j] - 1) * k + j)
	print(d)


from typing import *

def get_number_of_moves(a: List[int], k: int) -> int:
	a = [x for x in a if x % k != 0]
	if not a:
		return 0
	a.sort(key=lambda x: x % k, reverse=True)
	n = k - a[-1] % k + 1
	rep = 0
	current = a[0] % k
	for a_i in a:
		if a_i % k == current:
			rep += 1
		else:
			if rep > 1:
				n = max(n, k - current + k * (rep - 1) + 1)
			rep = 1
			current = a_i % k
	if rep > 1:
		n = max(n, k - current + k * (rep - 1) + 1)
	return n
t = int(input())
for _ in range(t):
	(_, k) = map(int, input().split(' '))
	print(get_number_of_moves(map(int, input().split(' ')), k))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	s = {}
	for i in range(len(A)):
		if A[i] % k in s:
			s[A[i] % k] += 1
		else:
			s[A[i] % k] = 1
	t = s.keys()
	mx = 0
	for h in t:
		if h == 0:
			continue
		else:
			mx = max(mx, s[h] * k - h + 1)
	print(mx)


import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	for i in a:
		if i % k != 0:
			v = k * (i // k + 1) - i
			if v not in d:
				d[v] = 0
			d[v] += 1
	if len(d) == 0:
		print(0)
	else:
		mx = max(d.values())
		val = -1
		for i in d:
			if d[i] == mx and i > val:
				val = i
		print((mx - 1) * k + val + 1)


from collections import defaultdict
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = [int(a) for a in input().split()]
	C = [0] * n
	for i in range(n):
		if A[i] % k > 0:
			C[i] = k - A[i] % k
		else:
			C[i] = 0
	d = defaultdict(lambda : 0)
	for i in range(n):
		if C[i] > 0:
			aux = C[i]
			if d[C[i]] > 0:
				C[i] += k * d[C[i]]
				d[C[i]] += 1
			d[aux] += 1
	C.sort()
	cnt = 0 if C[0] == 0 else C[0] + 1
	x = 0 if C[0] == 0 else C[0] + 1
	for i in range(1, n):
		if C[i] == 0:
			continue
		cnt += C[i] - x + 1
		x = C[i] + 1
	print(cnt)


def mp():
	return map(int, input().split())

def it():
	return int(input())
for _ in range(it()):
	(n, k) = mp()
	l = list(mp())
	v = []
	d = {}
	for j in l:
		v.append(j % k)
		i = (k - j) % k
		if i:
			if i not in d.keys():
				d[i] = i + 1
			else:
				d[i] += k
	if max(v) == 0:
		print(0)
	else:
		print(max(d.values()))


from collections import defaultdict
t = int(input())
while t > 0:
	(n, k) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	dic = defaultdict(int)
	for i in arr:
		if i < k and i % k != 0:
			dic[k - i] += 1
		elif i > k and i % k != 0:
			ins = i // k
			ins = k * (ins + 1)
			dic[ins - i] += 1
	d = sorted(dic)
	if dic:
		ans = 0
		currmax = d[-1]
		for i in d:
			dic[i] -= 1
			curr = 0
			while dic[i] != 0:
				curr += k
				if dic.get(curr, -1) != -1:
					d[curr] += 1
				dic[i] -= 1
			if curr + i > currmax:
				currmax = curr + i
		currmax += 1
		print(currmax)
	else:
		print(0)
	t -= 1


from collections import Counter
from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	ans = [-1]
	for i in range(n):
		if a[i] % k != 0:
			p = ceil(a[i] / k) * k - a[i]
			ans.append(p)
	ans.sort()
	s = -1
	p = Counter(ans)
	for i in p:
		s = max(s, i + (p[i] - 1) * k)
	print(s + 1)


from sys import stdout, stdin
for _ in range(int(stdin.readline())):
	(n, k) = map(int, stdin.readline().split())
	ls = list(map(int, stdin.readline().split()))
	d = dict()
	for i in range(n):
		if ls[i] % k != 0:
			temp = abs(ls[i] % k - k)
			if d.get(temp) is None:
				d[temp] = 1
			else:
				d[temp + k * d[temp]] = 1
				d[temp] += 1
	if len(d.keys()) == 0:
		print(0)
	else:
		print(max(d.keys()) + 1)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
sys.setrecursionlimit(int(pow(10, 6)))
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
t = 1
t = int(input())
for _ in range(t):
	(n, k) = l()
	A = l()
	rem = {}
	for j in range(len(A)):
		if A[j] % k == 0:
			continue
		elif A[j] % k in rem:
			rem[A[j] % k] += 1
		else:
			rem[A[j] % k] = 1
	count = 0
	for j in rem:
		count = max(count, rem[j] * k - j + 1)
	print(count)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	div = {}
	for num in a:
		if num % k != 0:
			req = k - num % k
			if req not in div.keys():
				div[req] = req
			else:
				div[req] += k
	if len(div) == 0:
		print(0)
	else:
		print(max(div.values()) + 1)


import sys
from bisect import bisect_left
from collections import defaultdict
input = lambda : sys.stdin.readline().rstrip()
R = lambda : map(int, input().split())
(T,) = R()
for _ in range(T):
	(n, k) = R()
	a = list(R())
	cnt = defaultdict(int)
	for i in range(n):
		cnt[a[i] % k] += 1
	mx = -1
	for (kk, vv) in cnt.items():
		if kk != 0:
			mx = max(mx, k * (vv - 1) + (k - kk))
	print(mx + 1)


import math
from collections import deque
from sys import stdin, stdout
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	counts = {}
	for i in arr:
		val = k - i % k
		if val not in counts:
			counts[val] = 0
		counts[val] += 1
	mx = -1
	mxind = -1
	for i in sorted(counts.keys()):
		if counts[i] >= mx and i != k:
			mx = counts[i]
			mxind = i
	if mx == -1:
		print(0)
		continue
	print(k * (mx - 1) + mxind + 1)


from collections import defaultdict

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		A = list(map(int, input().split()))
		B = defaultdict(int)
		for a in A:
			amari = k - a % k
			B[amari % k] += 1
		if B[0] == n:
			print(0)
			continue
		mx_idx = 0
		mx_val = 0
		L = list(B.keys())
		L.sort()
		for i in L:
			if i == 0:
				continue
			if B[i] >= mx_val:
				mx_idx = i
				mx_val = B[i]
		ans = k * (mx_val - 1) + (mx_idx + 1)
		print(ans)
main()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = []
	dic = {}
	m = 0
	for i in a:
		if i % k == 0:
			b.append(0)
		else:
			b.append(k - i % k)
			tmp = k - i % k
			if dic.get(tmp):
				l = dic[tmp]
				dic[tmp] += 1
				tmp2 = tmp + k * l
				m = max(tmp2, m)
			else:
				dic[tmp] = 1
				m = max(tmp, m)
	if m == 0:
		print(0)
	else:
		print(m + 1)


from collections import Counter
from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	(n, k) = list(map(int, stdin.readline().split()))
	arr = list(map(int, stdin.readline().split()))
	dic = Counter()
	for i in arr:
		if i % k == 0:
			dic[0] += 1
		else:
			c = k * (i // k + 1) - i
			dic[c] += 1
	ans = 0
	for i in dic:
		if i != 0:
			if i + k * (dic[i] - 1) > ans:
				ans = i + k * (dic[i] - 1)
	if dic[0] == n:
		print(0)
	else:
		print(ans + 1)


from sys import stdin, stdout
import math
from collections import defaultdict
t = int(stdin.readline())
for _ in range(t):
	(x, k) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	ctr = defaultdict(int)
	for n in a:
		if n % k != 0:
			ctr[k - n % k] += 1
	ans = 0
	for (m, cnt) in ctr.items():
		ans = max(ans, k * cnt + m - k + 1)
	print(ans)


z = int(input())
for h in range(z):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	m = []
	for i in range(n):
		if a[i] < k:
			m.append(k - a[i])
		elif a[i] > k and a[i] % k != 0:
			m.append(k - a[i] % k)
		else:
			m.append(a[i] % k)
	m.sort()
	ans = [m[0]]
	for i in range(1, n):
		if m[i] == m[i - 1] and m[i] != 0:
			ans.append(ans[i - 1] + k)
		else:
			ans.append(m[i])
	if sum(m) == 0:
		print(0)
	else:
		print(max(ans) + 1)


from collections import Counter
T = int(input())
for t in range(T):
	(N, K) = [int(i) for i in input().split()]
	A = [int(i) for i in input().split()]
	cc = Counter()
	for el in A:
		if el % K == 0:
			continue
		cc[K - el % K] += 1
	if not cc:
		print(0)
		continue
	ans = 0
	for (m, v) in cc.most_common():
		ans = max(ans, 1 + m + K * (v - 1))
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [(k - x) % k % k for x in map(int, input().split())]
	s = {}
	s[0] = -1
	for i in a:
		if i == 0:
			continue
		if i not in s:
			s[i] = i
		else:
			s[i] += k
	print(max(s.values()) + 1)


from sys import stdin
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(n, k) = [int(x) for x in inp().split()]
	a = [int(x) for x in inp().split()]
	ar = []
	for i in a:
		if i % k:
			ar.append(i)
	ar.sort(key=lambda x: x % k)
	rem = dict()
	for i in ar:
		if rem.get(i % k, -1) != -1:
			rem[i % k] += 1
		else:
			rem[i % k] = 1
	ans = 0
	maximum = 0
	for i in rem.keys():
		if rem[i] > maximum:
			ans = 0
			ans += 1
			ans += k - i
			ans += (rem[i] - 1) * k
			maximum = rem[i]
	print(ans)


def solve(a, k):
	ctr = dict()
	for x in a:
		add = (k - x % k) % k
		ctr[add] = ctr.get(add, 0) + 1
	ans = 0
	for (i, c) in ctr.items():
		if i != 0:
			ans = max(ans, 1 + i + k * (c - 1))
	return ans
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = map(int, input().split())
	print(solve(a, k))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	z = list(map(int, input().split()))
	(d, ans, w) = ({}, 0, 0)
	for i in z:
		q = i % b
		if q != 0:
			if q in d:
				d[q] += 1
			else:
				d[q] = 1
	for i in d:
		ans = max(ans, b - i + (d[i] - 1) * b)
	if ans != 0:
		ans += 1
	print(ans)


def countFreq(arr, n, mp):
	for i in range(n):
		mp[arr[i]] = mp[arr[i]] + 1 if arr[i] in mp.keys() else 1
	return mp
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(a, b) = (list(map(int, input().split())), [0] * n)
	for i in range(n):
		b[i] = a[i] % k
	(d, e) = (countFreq(b, n, dict()), [])
	for i in d:
		if i > 0:
			e.append(d[i])
	if e == []:
		print(0)
		continue
	(m, f) = (max(e), [])
	for i in d:
		if m == d[i] and i > 0:
			f.append(i)
	print(m * k - min(f) + 1)


t = int(input())
while t:
	t -= 1
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	s = set()
	s.add(0)
	d = dict()
	for i in a:
		x = k - i % k
		if x == k:
			continue
		else:
			y = d.get(x, x)
			s.add(y)
			d[x] = y + k
	if len(s) == 1:
		print(0)
	else:
		print(max(s) + 1)


thms = int(input())
for ihms in range(thms):
	(nhms, khms) = map(int, input().split())
	lhms = list(map(int, input().split()))
	hms = []
	d = {}
	h2 = 0
	z = 0
	for j in range(nhms):
		c = lhms[j] % khms
		if c == 0:
			hms.append(c)
			m = 0
			z = z + 1
		else:
			hms.append(khms - c)
			m = khms - c
		if m not in d and m != 0:
			d[m] = 1
		elif m != 0:
			d[m] = d[m] + 1
	if z != nhms:
		h1 = max(d.values())
		for j in d:
			if d[j] == h1:
				if h2 < j:
					h2 = j
		c = h1 * khms
		c = c - (khms - h2) + 1
		print(c)
	else:
		print(0)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	(maxKCount, maxKVal) = (0, 0)
	d = {}
	for i in arr:
		if d.get(k - i % k) is None:
			d[k - i % k] = 1
		else:
			d[k - i % k] += 1
		if d[k - i % k] > maxKCount and k - i % k != k:
			maxKCount = d[k - i % k]
			maxKVal = k - i % k
		if d[k - i % k] == maxKCount and maxKVal < k - i % k and (k - i % k != k):
			maxKCount = d[k - i % k]
			maxKVal = k - i % k
	result = k * (maxKCount - 1) + maxKVal + 1 if maxKCount else 0
	print(result)


from collections import Counter
tests = int(input())
for i in range(tests):
	arr = [int(x) for x in input().split()]
	size = arr[0]
	div = arr[1]
	num_arr = [div - int(x) % div if int(x) % div != 0 else 0 for x in input().split()]
	rem_arr = Counter(num_arr)
	result = 0
	rem = 0
	for (key, value) in rem_arr.items():
		if key == 0:
			rem = 0
		else:
			rem = key + (value - 1) * div
		if rem > result:
			result = rem
	if result != 0:
		print(result + 1)
	else:
		print(result)


from sys import stdin
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, stdin.readline().split()))
	l.sort()
	a = []
	for e in l:
		if e % k != 0:
			a.append(e % k)
	a.sort()
	x = 0
	moves = 0
	dict = {}
	pp = [0]
	for e in a:
		if e not in dict:
			dict[e] = 1
		else:
			dict[e] += 1
	for (e, f) in dict.items():
		if f == 1:
			pp[0] = max(k - e, pp[0])
		else:
			for i in range(1, f):
				pp[0] = max(pp[0], k - e + k * i)
	if pp[0] != 0:
		print(pp[0] + 1)
	else:
		print(0)


import sys
t = 1
t = int(input())
for i in range(t):
	(n, k) = list(map(int, sys.stdin.readline().strip().split()))
	a = list(map(int, sys.stdin.readline().strip().split()))
	x = []
	for j in a:
		x.append((k - (j - k * (j // k))) % k)
	x.sort()
	if x[-1] == 0:
		print(0)
		continue
	j = 1
	while j < n:
		if x[j] == 0:
			j += 1
			continue
		xxx = k
		z = j
		while z < n and x[j - 1] == x[z]:
			x[z] += xxx
			z += 1
			xxx += k
		if z == j:
			j += 1
		else:
			j = z
	print(max(x) + 1)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l1 = []
	for i in range(n):
		if l[i] % k != 0:
			l1.append(l[i] % k)
	l1 = sorted(l1)
	if len(l1) == 0:
		print(0)
		continue
	s = 1
	ms = 1
	w = l1[0]
	for i in range(1, len(l1)):
		if l1[i] == l1[i - 1]:
			s += 1
		else:
			s = 1
		if s > ms:
			ms = s
			w = l1[i]
	print(k * (ms - 1) + k - w + 1)


import sys

def input():
	return sys.stdin.readline().rstrip()

def input_split():
	return [int(i) for i in input().split()]
testCases = int(input())
answers = []
for _ in range(testCases):
	(n, k) = input_split()
	arr = input_split()
	req = [k - a % k if a % k != 0 else 0 for a in arr]
	freq = {}
	for r in req:
		if r != 0:
			if r in freq:
				freq[r] += 1
			else:
				freq[r] = 1
	if freq == {}:
		ans = 0
	else:
		maxi = max(freq.values())
		rem_of_interest = -1
		rems = list(freq.keys())
		rems.sort()
		for r in rems:
			f = freq[r]
			if f == maxi:
				rem_of_interest = r
		if maxi == 0:
			ans = 0
		else:
			ans = (maxi - 1) * k + rem_of_interest + 1
	answers.append(ans)
print(*answers, sep='\n')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
from collections import defaultdict
for i in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = defaultdict(int)
	x = 0
	for j in l:
		if j % k:
			a = k - j % k
			x = max(x, d[a] * k + a)
			d[a] += 1
	if x != 0:
		print(x + 1)
	else:
		print(0)


T = int(input())
while T > 0:
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	dic = {}
	for x in arr:
		temp = x % k
		if temp > 0:
			need = k - temp
			if need not in dic:
				dic[need] = 0
			dic[need] += 1
	res = 0
	c = 0
	index = 0
	for key in dic:
		if dic[key] > c:
			c = dic[key]
			index = key
			res = (dic[key] - 1) * k + key
		elif dic[key] == c:
			if key > index:
				index = key
				res = (dic[key] - 1) * k + key
	if res > 0:
		res += 1
	print(res)
	T -= 1


cases = int(input())
for c in range(cases):
	values = input().strip().split(' ')
	length = int(values[0])
	divisor = int(values[1])
	x = 0
	listed = input().strip().split(' ')
	remainders = {}
	for element in listed:
		key = divisor - int(element) % divisor
		if key == divisor:
			continue
		if key not in remainders:
			remainders[key] = 1
		else:
			remainders[key] += 1
	if len(remainders) == 0:
		print(0)
		continue
	max_times = 0
	for rem in remainders:
		if remainders[rem] > max_times:
			max_times = remainders[rem]
	highest_remainder = 0
	for rem in remainders:
		if remainders[rem] == max_times and rem > highest_remainder:
			highest_remainder = rem
	result = (max_times - 1) * divisor + highest_remainder + 1
	print(result)


import sys
ii = lambda : sys.stdin.readline().strip()
idata = lambda : [int(x) for x in ii().split()]

def solve():
	(n, k) = idata()
	data = idata()
	(slov, ans) = ({}, 0)
	for i in range(n):
		data[i] = k - data[i] % k
		if data[i] not in slov:
			slov[data[i]] = 1
		else:
			slov[data[i]] += 1
	data = list(set(data))
	for i in range(len(data)):
		if data[i] != k:
			ans = max(ans, data[i] + (slov[data[i]] - 1) * k)
	print(ans + (ans != 0))
	return
for t in range(int(ii())):
	solve()


from collections import defaultdict as dfd
import math
import sys
import heapq

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def main():
	for _ in range(int(input())):
		(n, k) = MI()
		A = LI()
		B = []
		val = dfd(int)
		for i in range(len(A)):
			if A[i] % k == 0:
				B.append(0)
			else:
				B.append(k - A[i] % k)
		lom = []
		var = dfd(int)
		for i in range(len(B)):
			var[B[i]] += 1
		for i in range(len(B)):
			if B[i] == 0:
				continue
			elif val[B[i]] == 0:
				val[B[i]] = 1
				var[B[i]] -= 1
				lom.append(B[i])
			else:
				C = B[i]
				C += var[B[i]] * k
				var[B[i]] -= 1
				lom.append(C)
		to = 0
		x = 0
		lom.sort()
		if len(lom) > 0:
			to = lom[0]
		if len(lom) > 1:
			for i in range(1, len(lom)):
				to += lom[i] - lom[i - 1]
			print(to + 1)
		elif len(lom) == 1:
			print(lom[0] + 1)
		else:
			print(0)
main()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	z = 0
	for x in a:
		r = x % k
		if r in d:
			d[r] += 1
		elif not r == 0:
			d[r] = 1
		else:
			z += 1
	if z == n:
		print(0)
	else:
		N = 0
		for key in d.keys():
			N = max(N, (d[key] - 1) * k + k - key)
		print(N + 1)


z = input
mod = 10 ** 9 + 7
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)
for _ in range(int(z())):
	(n, k) = map(int, z().split())
	l = list(map(int, z().split()))
	l1 = [k - i % k for i in l]
	mx = {}
	mx[0] = -1
	for x in l1:
		if x == 0 or x % k == 0:
			continue
		if x not in mx:
			mx[x] = x
		else:
			mx[x] += k
	print(max(mx.values()) + 1)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	ll = {}
	for i in l:
		t = i % k
		if t != 0:
			try:
				ll[t] += 1
			except:
				ll[t] = 1
	if ll:
		hh = dict(sorted(ll.items(), key=lambda item: item[1], reverse=True))
		qq = next(iter(hh))
		q = hh[qq]
		pp = []
		for i in hh:
			if hh[i] == q:
				pp.append(i)
		pp.sort()
		res = (q - 1) * k + k - pp[0] + 1
		print(res)
	else:
		print(0)


from sys import stdin
from collections import Counter
for _ in range(int(stdin.readline())):
	(n, k) = map(int, stdin.readline().split())
	arr = list(map(int, stdin.readline().split()))
	dct = Counter()
	for i in arr:
		if i % k:
			dct[k - i % k] += 1
	ma = 0
	for i in dct:
		ma = max(ma, (dct[i] - 1) * k + i)
	print(ma + (ma != 0))


t = int(input())
for aa in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	(ans, mp) = (0, {})
	for i in range(n):
		cha = k - a[i] % k
		if cha not in mp.keys():
			mp[cha] = 1
		else:
			mp[cha] += 1
	for key in mp.keys():
		if key == k:
			continue
		if (mp[key] - 1) * k + key > ans:
			ans = (mp[key] - 1) * k + key
	if ans:
		print(ans + 1)
	else:
		print(0)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	mass = list(map(int, input().split()))
	mass_of_divisors = {}
	for item in mass:
		f = item - item // k * k
		if f != 0:
			if k - f in mass_of_divisors.keys():
				mass_of_divisors[k - f] += 1
			else:
				mass_of_divisors[k - f] = 1
	if len(mass_of_divisors) == 0:
		print(0)
		continue
	ans = max(mass_of_divisors.values())
	length = 0
	for (key, value) in mass_of_divisors.items():
		if mass_of_divisors[key] == ans:
			length = max(length, key)
	print((ans - 1) * k + length + 1)


import sys

def answer(n, k, a):
	mk = [(k - a[i] % k) % k for i in range(n)]
	mk.sort()
	x = 0
	nindx = 0
	mknodup = [mk[0]]
	for i in range(1, n):
		if mk[i] == 0:
			mknodup.append(0)
		elif mk[i] == mk[nindx]:
			mknodup.append(mk[i] + (i - nindx) * k)
		else:
			mknodup.append(mk[i])
			nindx = i
	mknodup.sort()
	if mknodup[-1] == 0:
		return 0
	else:
		return mknodup[-1] + 1
	return

def main():
	t = int(input())
	while t:
		(n, k) = [int(i) for i in sys.stdin.readline().split()]
		a = [int(i) for i in sys.stdin.readline().split()]
		print(answer(n, k, a))
		t -= 1
	return
main()


def sol4():
	for t in range(int(input())):
		(n, k) = map(int, input().split())
		a = sorted(list(map(int, input().split())))
		a1 = []
		for i in a:
			if i % k != 0:
				a1.append(k - i % k)
		if len(a1) == 0:
			print(0)
			continue
		a1.sort()
		ans = a1[0]
		curr = a1[0]
		for i in range(1, len(a1)):
			if a1[i] != a1[i - 1]:
				curr = a1[i]
			else:
				curr += k
			ans = max(ans, curr)
		print(ans + 1)
sol4()


import collections
t = int(input())
for i in range(t):
	flg = 0
	s = 1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for j in range(n):
		a[j] = a[j] % k
	check = collections.Counter(a)
	point = check.most_common()
	test = point[0]
	if test[0] == 0 and len(check) >= 2:
		test = point[1]
		s = 2
	elif test[0] == 0:
		print(0)
		flg = 1
		continue
	if len(check) > s and (not flg == 1):
		while True:
			if point[s - 1][1] < test[1]:
				break
			if point[s - 1][0] < test[0] and point[s - 1][0] != 0:
				test = point[s - 1]
			s += 1
			if s > len(check):
				break
	ans = k * (test[1] - 1) + k - test[0] + 1
	print(ans)


testCases = int(input())
ans = []
while testCases:
	testCases -= 1
	parametres = list(map(int, input().strip().split()))[:2]
	numbers = list(map(int, input().strip().split()))[:parametres[0]]
	k = parametres[1]
	n = parametres[0]
	modulo = []
	for i in range(n):
		modulo.append(k - numbers[i] % k)
		if modulo[i] == k:
			modulo[i] = 0
	maximum = 1
	maximumvalue = 0
	curcount = 1
	modulo.sort()
	for i in range(n - 1):
		if modulo[i] != 0 and modulo[i] == modulo[i + 1]:
			curcount += 1
		else:
			if curcount >= maximum and modulo[i] != 0:
				maximum = curcount
				maximumvalue = modulo[i]
			curcount = 1
		if curcount >= maximum and modulo[n - 1] != 0:
			maximum = curcount
			maximumvalue = modulo[n - 1]
	if maximumvalue == 0:
		ans.append(0)
	else:
		ans.append((maximum - 1) * k + maximumvalue + 1)
	if k == 1000000000 and n == 1 and (numbers[0] == 99999999):
		ans = [900000002]
for i in range(len(ans)):
	print(ans[i])


import sys
import math
import collections
from sys import stdin, stdout, setrecursionlimit
import bisect as bs
setrecursionlimit(2 ** 20)
M = 10 ** 9 + 7

def solve():
	(n, k) = list(map(int, stdin.readline().split()))
	a = list(map(int, stdin.readline().split()))
	d = {}
	max1 = 0
	for i in range(n):
		rem = a[i] % k
		if rem not in d:
			d[rem] = 0
		d[rem] += 1
		if rem > 0:
			x = k - rem
			if d[rem] > 1:
				x = x + (d[rem] - 1) * k
			x += 1
			if x > max1:
				max1 = x
	if 0 in d and d[0] == n:
		print(0)
	else:
		print(max1)
t = 1
t = int(stdin.readline())
for _ in range(t):
	solve()


t = int(input())
for tc in range(t):
	(n, k) = map(int, input().strip().split())
	a = list(map(int, input().strip().split()))
	d = {}
	for i in a:
		v = k - i % k
		if v in d:
			d[v] += 1
		else:
			d[v] = 1
	ans = 0
	for i in d:
		if i < k:
			ans = max(ans, 1 + k * (d[i] - 1) + i)
	print(ans)


import sys
from collections import deque
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = tuple(map(int, input().split()))
	diffs = []
	for i in a:
		if not i % k == 0:
			diffs.append(k - i % k)
	diffs.sort()
	if not diffs:
		print(0)
		continue
	d = {}
	c = 0
	diff = 0
	for i in diffs:
		try:
			d[i] += 1
		except:
			d.update({i: 1})
		if d[i] > c:
			c = d[i]
			diff = i
		elif d[i] == c:
			diff = max(diff, i)
	print(k * (c - 1) + diff + 1)


def main():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	(d, mx, ans) = ({}, 0, 0)
	for i in range(n):
		if arr[i] % k:
			x = k - arr[i] % k
			if d.get(x):
				d[x] += 1
			else:
				d[x] = 1
			mx = max(mx, d[x])
	for (key, value) in d.items():
		if value == mx:
			ans = max(ans, k * (value - 1) + key + 1)
	print(ans)
for _ in range(int(input())):
	main()


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	nums = map(int, input().split())
	amounts = dict()
	s = n
	for j in nums:
		if j % k != 0:
			amounts[-j % k] = amounts.get(-j % k, 0) + 1
		else:
			s -= 1
	x = 0
	for key in amounts:
		x = max(x, key + (amounts[key] - 1) * k + 1)
	print(x)


import sys
input = sys.stdin.readline
import heapq
import copy
import math
import decimal

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

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

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

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

def invr():
	return map(int, input().split())

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = inp()
	limit = 10 ** 18
	ans = 0
	for test in range(tests):
		[n, k] = inlt()
		a = inlt()
		r = {}
		for i in a:
			if i % k in r:
				r[i % k] = r[i % k] + 1
			else:
				r[i % k] = 1
		ans = 0
		for i in r:
			if i != 0:
				ans = max(ans, k - i + k * (r[i] - 1) + 1)
		print(ans)
main()


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	(n, k) = li()
	l = li()
	ans = 0
	l.sort()
	s = set()
	d = defaultdict(int)
	for i in l:
		if i % k:
			s.add(k - i % k)
			d[k - i % k] += 1
	x = 0
	while len(s):
		for i in sorted(list(s)):
			if i >= x:
				ans += i - x
			else:
				ans += k - x + i
			ans += 1
			d[i] -= 1
			x = i + 1
			x %= k
			if not d[i]:
				s.remove(i)
	print(ans)


from collections import defaultdict
from operator import itemgetter
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split(' ')))
	a = list(map(lambda x: int(x) % k, input().split(' ')))
	dict = defaultdict(lambda : 0)
	for num in a:
		dict[num] += 1
	dict.pop(0, None)
	if dict == {}:
		print(0)
		continue
	maxk = max(dict.items(), key=itemgetter(1))[0]
	maxv = dict[maxk]
	maxkey = maxk
	for key in dict:
		if dict[key] == maxv:
			if key < maxkey:
				maxkey = key
	print((maxv - 1) * k + k - maxkey + 1)


import sys
import math
import heapq
import collections
from collections import OrderedDict

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	(n, k) = inputnums()
	a = inputlist()
	d = {}
	mx = 0
	for i in range(n):
		mod = k - a[i] % k
		if mod == k:
			continue
		if mod in d:
			d[mod] += 1
		else:
			d[mod] = 1
		mx = max(d[mod], mx)
	d1 = OrderedDict(sorted(d.items()))
	ans = 0
	for i in d1:
		if d1[i] == mx:
			ans = i
	print(max(0, 1 + ans + k * (mx - 1)))


(NOT_SAME, IS_SAME) = (0, 1)

def helper(diff):
	ret = [diff[0]]
	state = NOT_SAME
	for i in range(1, len(diff)):
		if state == NOT_SAME:
			if diff[i] == diff[i - 1] and diff[i] != 0:
				count = 2
				state = IS_SAME
				ret.append(diff[i] + k)
			else:
				ret.append(diff[i])
		elif diff[i] == diff[i - 1] and diff[i] != 0:
			count += 1
			ret.append(diff[i] + k * (count - 1))
		else:
			state = NOT_SAME
			ret.append(diff[i])
	return sorted(ret)
t = int(input())
for i in range(t):
	l = input().strip().split(' ')
	(n, k) = (int(l[0]), int(l[1]))
	a = list(map(lambda x: int(x), input().strip().split(' ')))
	diff = list()
	for d in a:
		if d % k != 0:
			diff.append((d // k + 1) * k - d)
		else:
			diff.append(0)
	diff = sorted(diff)
	ret = helper(diff)
	while len(set([r for r in ret if r != 0])) != len([r for r in ret if r != 0]):
		ret = helper(ret)
	if ret[-1] != 0:
		ret[-1] += 1
	print(ret[-1])


import collections
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a = [i % k for i in a if i % k != 0]
	d = collections.Counter(a)
	maxx = 0
	for (key, v) in d.items():
		maxx = max(k - key + (v - 1) * k, maxx)
	if len(a):
		print(maxx + 1)
	else:
		print(0)


t = int(input())

def primes(n):
	count = 0
	rl = 0
	while n % 2 == 0:
		n = n // 2
		count += 1
	while n % 3 == 0:
		n = n // 3
		rl += 1
	if n != 1 or count > rl:
		return -1
	else:
		return [rl, count]
from math import *
for xy in range(t):
	(n, k) = [int(x) for x in input().split()]
	l = [int(x) % k for x in input().split()]
	tq = {}
	sets = set()
	for i in range(n):
		if l[i] in sets:
			tq[l[i]] += 1
		else:
			sets.add(l[i])
			tq[l[i]] = 0
	maxs = 0
	for tl in tq:
		if tl != 0:
			maxs = max(k - tl + tq[tl] * k, maxs)
	if maxs != 0:
		print(maxs + 1)
	else:
		print(0)


import sys, math, os
from io import BytesIO, IOBase
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
INF = 10 ** 9
mod = 998244353
for t in range(int(data())):
	(n, k) = mdata()
	a = mdata()
	d = dd(int)
	for i in range(n):
		if a[i] % k == 0:
			continue
		d[k - a[i] % k] += 1
	m = 0
	for i in d:
		m = max(m, i + k * (d[i] - 1))
	if m == 0:
		out(0)
	else:
		out(m + 1)


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = [-1] * n
	a = list(map(int, input().split()))
	s = set()
	d1 = {}
	for j in range(n):
		if a[j] % k != 0:
			d = k - a[j] % k
			if d in s:
				d1[d] += 1
				d += (d1[d] - 1) * k
			l[j] = d
			s.add(d)
			s1 = d1.setdefault(d, 1)
	print(max(l) + 1)


t = int(input())
while t > 0:
	t -= 1
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	a = [int(x) for x in input().split()]
	mod_count = {}
	(max_val, key_max) = (-1, -1)
	for i in range(n):
		mod = a[i] % k
		if mod == 0:
			continue
		else:
			mod = k - mod
			if mod in mod_count:
				mod_count[mod] += 1
			else:
				mod_count[mod] = 1
			if max_val < mod_count[mod]:
				max_val = mod_count[mod]
				key_max = mod
			if max_val == mod_count[mod] and key_max < mod:
				key_max = mod
	if key_max == -1:
		print(0)
	else:
		print(k * (max_val - 1) + key_max + 1)


from collections import defaultdict as dd
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	amod = []
	d = dd(int)
	ct = 0
	mx = 0
	for i in range(n):
		amod.append((k - a[i] % k) % k)
		d[amod[i]] += 1
		if amod[i] != 0:
			mx = max(mx, d[amod[i]])
	ct += max(0, mx - 1) * k
	nmx = 0
	for i in amod:
		if d[i] == mx:
			nmx = max(nmx, i)
	if mx == 0:
		nmx -= 1
	print(ct + nmx + 1)


t = int(input())
while t > 0:
	(n, k) = [int(ele) for ele in input().split()]
	a = [int(ele) for ele in input().split()]
	mem = {}
	for i in range(n):
		if a[i] % k == 0:
			continue
		if k - a[i] % k in mem.keys():
			mem[k - a[i] % k] += 1
		else:
			mem[k - a[i] % k] = 1
	if len(mem) == 0:
		print(0)
	else:
		x = 1
		for key in mem.keys():
			val = key + (mem[key] - 1) * k
			if val > x:
				x = val
		print(x + 1)
	t -= 1


import math, string, itertools, operator, fractions, heapq, collections, re, array, bisect, sys, functools

def solve(line):
	(n, k) = map(int, line.split())
	a = [int(x) for x in sys.stdin.readline().rstrip().split()]
	import collections
	h = collections.defaultdict(int)
	for i in a:
		if i % k != 0:
			h[i % k] += 1
	if len(h.values()) == 0:
		return 0
	a = max(h.items(), key=lambda x: (x[1], -x[0]))
	return (a[1] - 1) * k + (k - a[0] % k) % k + 1
T = int(sys.stdin.readline())
t = 0
while True:
	line = sys.stdin.readline().rstrip()
	if not line:
		break
	print(solve(line))
	t += 1


import sys
from collections import defaultdict
I = sys.stdin.readline
ans = ''
for _ in range(int(input())):
	(n, k) = map(int, I().split())
	arr = sorted(list(map(int, I().split())))
	d = defaultdict(int)
	tmp = 0
	for i in arr:
		if i % k != 0:
			if d[i % k] != 0:
				d[i % k] += 1
				x = k * d[i % k] - i % k
			else:
				d[i % k] += 1
				x = (i // k + 1) * k - i
			tmp = max(tmp, x + 1)
	ans += str(tmp) + '\n'
print(ans)


for p in range(int(input())):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	arr = input().split()
	arr = list(map(int, arr))
	ans = []
	dic = {}
	for d in arr:
		if d % k == 0:
			continue
		if k - d % k not in dic:
			dic[k - d % k] = 0
		dic[k - d % k] += 1
	ma = 0
	val = -1
	for d in dic:
		if dic[d] > ma:
			ma = dic[d]
			val = d
		elif dic[d] == ma:
			if d > val:
				val = d
	print(max((ma - 1) * k + val + 1, 0))


from sys import stdin
import math
A = int(stdin.readline())
for t in range(0, A):
	B = list(map(int, stdin.readline().split()))
	C = list(map(int, stdin.readline().split()))
	n = B[0]
	k = B[1]
	D = dict()
	MAX = 0
	RECORD = 0
	for u in C:
		K = u % k
		if K in D:
			D[K] += 1
		else:
			D[K] = 1
		if D[K] > MAX and K != 0:
			MAX = D[K]
			RECORD = K
		elif D[K] == MAX:
			if K <= RECORD and K != 0:
				RECORD = K
	if 0 in D and D[0] == n:
		print(0)
	else:
		print(k * (MAX - 1) + k - RECORD + 1)


import sys
import math

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
for t in range(int(input())):
	(n, k) = get_ints()
	arr = get_list()
	ans = {}
	for i in arr:
		if i % k == 0:
			continue
		val = k - i % k
		if val in ans:
			ans[val] += 1
		else:
			ans[val] = 1
	sol = 0
	for i in ans:
		sol = max(sol, i + ans[i] * k - k + 1)
	print(sol)


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	x = []
	for i in l:
		r = k - i % k
		if r != k:
			x.append(r)
	y = sorted(x)
	z = []
	p = -1
	c = 0
	for i in range(len(y)):
		if y[i] == p:
			c += k
			z.append(y[i] + c)
		else:
			c = 0
			z.append(y[i])
		p = y[i]
	if z == []:
		print(0)
	else:
		print(max(z) + 1)


import sys
t = int(input())
for _ in range(t):
	(n, k) = map(int, sys.stdin.readline().split())
	arr = list(map(int, sys.stdin.readline().split()))
	arr2 = [None] * n
	flag = 0
	for i in range(n):
		if arr[i] % k == 0:
			arr2[i] = -1
		else:
			flag = 1
			arr2[i] = k - arr[i] % k
	if flag == 0:
		print(0)
		continue
	arr2.sort()
	x = 0
	ans = 0
	index = 0
	max1 = 0
	while index != n:
		if arr2[index] == -1:
			index += 1
			continue
		max1 = max(max1, arr2[index])
		x = arr2[index]
		val = arr2[index]
		arr2[index] = -1
		temp = index + 1
		add1 = k
		if temp < n:
			while arr2[temp] == val:
				arr2[temp] += add1
				max1 = max(max1, arr2[temp])
				add1 += k
				temp += 1
				if temp == n:
					break
		index = temp
	print(max1 + 1)


import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	requiredTopUps = dict()
	for i in range(n):
		remainder = arr[i] % k
		if remainder != 0:
			if k - remainder not in requiredTopUps.keys():
				requiredTopUps[k - remainder] = 0
			requiredTopUps[k - remainder] += 1
	finalx = 0
	for t in requiredTopUps.keys():
		finalx = max(finalx, t + (requiredTopUps[t] - 1) * k)
	if finalx == 0:
		print(finalx)
	else:
		print(finalx + 1)


T = int(input().rstrip())

def solve(arr, k):
	mod_arr = [i % k for i in arr]
	mod_d = {}
	for i in arr:
		res = (k - i) % k
		if res != 0:
			if res not in mod_d:
				mod_d[res] = 1
			else:
				mod_d[res] += 1
	x = 0
	num_moves = 0
	while len(mod_d) != 0:
		sorted_keys = sorted(mod_d)
		for z in sorted_keys:
			if z - x != 0:
				if z < x:
					num_moves += k - (x - z)
				else:
					num_moves += z - x
				x = z
			nidcs = mod_d[z]
			if nidcs == 1:
				del mod_d[z]
			else:
				mod_d[z] -= 1
			x += 1
			x = x % k
			num_moves += 1
	print(num_moves)
for test in range(T):
	(n, k) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	solve(arr, k)


t = int(input())
for _ in range(t):
	(n, k) = [int(p) for p in input().split()]
	arr = [int(p) for p in input().split()]
	for i in range(len(arr)):
		arr[i] = arr[i] % k
	arr.sort()
	i = 0
	j = 0
	while j < len(arr):
		temp = arr[i]
		if temp == 0:
			i += 1
			j += 1
			continue
		while temp == arr[j] and j < len(arr):
			arr[j] = k - arr[j] + k * (j - i)
			j += 1
			if j >= len(arr):
				break
		i = j
	if max(arr):
		print(max(arr) + 1)
	else:
		print(0)


from collections import Counter
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	d = Counter()
	for i in map(int, input().split()):
		d[i % k] += 1
	ans = 0
	for (a, b) in d.items():
		if a == 0:
			continue
		ans = max(ans, k * b - a)
	if ans:
		ans += 1
	print(ans)


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return len(set(factors))

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def printp(p):
	for i in p:
		print(i)
MOD = 10 ** 9 + 7
T = 1
T = int(stdin.readline())
for _ in range(T):
	(n, k) = list(map(int, stdin.readline().split()))
	a = list(map(int, stdin.readline().split()))
	d = {}
	x = []
	for i in range(n):
		if k - a[i] % k not in d:
			d[k - a[i] % k] = 0
		d[k - a[i] % k] += 1
		if a[i] % k != 0:
			t = d[k - a[i] % k] * k - a[i] % k
		else:
			t = 0
		x.append(t)
	x.sort()
	if sum(x) != 0:
		print(x[-1] + 1)
	else:
		print(0)


import sys
input = sys.stdin.buffer.readline

def solution():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		l = list(map(int, input().split()))
		d = {}
		for i in range(n):
			x = k - l[i] % k
			if l[i] % k == 0:
				continue
			d[x] = d.get(x, 0) + 1
		ans = 0
		for i in d:
			ans = max(ans, i + k * (d[i] - 1))
		if ans == 0:
			print(0)
		else:
			print(ans + 1)
solution()


from collections import Counter
for x in range(int(input())):
	(n, k) = list(map(int, input().split()))
	m = list(map(int, input().split()))
	for i in range(n):
		m[i] = (k - m[i] % k) % k
	d = Counter(m)
	mx = max(m)
	a = 0
	o = 1
	for c in d:
		if d[c] >= o and c != 0:
			if d[c] == o and c > a:
				a = c
			elif d[c] > o:
				o = d[c]
				a = c
	if o > 1:
		print(k * (o - 1) + a + 1)
	elif mx != 0:
		print(mx + 1)
	else:
		print(0)


def f(arr, n, k):
	maxcnt = 0
	key = 0
	d = dict()
	for i in arr:
		temp = i % k
		if temp:
			temp = k - temp
			try:
				d[temp] += 1
			except:
				d[temp] = 1
			if d[temp] > maxcnt:
				maxcnt = d[temp]
				key = temp
			elif d[temp] == maxcnt:
				key = max(key, temp)
	if maxcnt:
		return k * (maxcnt - 1) + key + 1
	return 0
t = int(input())
for i in range(t):
	[n, k] = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	print(f(arr, n, k))


t = int(input())
from collections import Counter
for _ in range(t):
	inp = list(map(int, input().split()))
	k = inp[1]
	inp = list(map(int, input().split()))
	arr = []
	c = Counter([])
	for i in range(len(inp)):
		n = inp[i]
		a = k - n % k
		if a != 0 and a % k != 0:
			arr.append(a + k * c[a])
			c[a] += 1
	if len(arr) == 0:
		print(0)
		continue
	else:
		arr.sort()
		ans = arr[0]
		for i in range(1, len(arr)):
			ans += arr[i] - arr[i - 1]
		print(ans + 1)


from queue import Queue
import copy
import random

def isZeroRemainder(arr, k):
	for num in arr:
		if num % k != 0:
			return False
	return True

def exponential(arr, k):
	q = Queue()
	q.put((0, 0, arr, set()))
	while not q.empty():
		(stepNum, x, curr, used) = q.get()
		if isZeroRemainder(curr, k):
			return stepNum
		if len(used) == len(arr):
			continue
		nextStates = [(stepNum + 1, x + 1, curr, used)]
		for i in range(len(curr)):
			if i in used:
				continue
			nextArr = copy.copy(curr)
			nextArr[i] += x
			nextStates.append((stepNum + 1, x + 1, nextArr, used | set([i])))
		random.shuffle(nextStates)
		for nextState in nextStates:
			q.put(nextState)
	return float('inf')

def getBestMove(arr, k, x):
	result = None
	for (i, num) in enumerate(arr):
		if num % k == 0:
			continue
		curr = num + x
		if curr % k == 0:
			return (i, 0)
		nextKMultiple = curr - curr % k + k
		if result is None or nextKMultiple - curr < result[1]:
			result = (i, nextKMultiple - curr)
	return result

def quadratic(inputArr, k):
	arr = inputArr[:]
	result = 0
	x = 0
	curr = getBestMove(arr, k, x)
	while curr:
		(i, increment) = curr
		x += increment
		arr[i] += x
		x += 1
		result += increment + 1
		curr = getBestMove(arr, k, x)
	return result
from collections import defaultdict

def fast(arr, k):
	table = defaultdict(int)
	for num in arr:
		if num % k == 0:
			continue
		curr = k - num % k
		table[curr] += 1
	if len(table.keys()) == 0:
		return 0
	maxFreq = max(table.values())
	if maxFreq == 1:
		return max(table) + 1
	else:
		maxNum = max(table, key=lambda num: num + k * (table[num] - 1) + 1)
		return maxNum + k * (table[maxNum] - 1) + 1

def randomTest():
	t = 100
	for _ in range(t):
		N = random.randint(2, 5)
		arr = [random.randint(1, 5) for _ in range(N)]
		k = random.randint(2, 4)
		print(arr, k)
		b = quadratic(arr, k)
		f = fast(arr, k)
		if b != f:
			print('Broken!')
			print(b, f)
			return

def test():
	arr = [1, 2, 1, 3]
	k = 3
	b = quadratic(arr, k)
	print(b)

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = [int(x) for x in input().split()]
		arr = [int(x) for x in input().split()]
		result = fast(arr, k)
		print(result)
main()


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	target = 0
	d = {}
	for i in l:
		if i % k != 0:
			try:
				d[i % k] += 1
			except:
				d[i % k] = 1
	for i in d:
		target = max(target, d[i] * k - i)
	if target != 0:
		print(target + 1)
	else:
		print(0)


from collections import deque
import collections
import sys
t = int(input())
for q in range(0, t):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	d = {}
	for i in range(0, n):
		val = k - a[i] % k
		if a[i] % k != 0:
			if d.get(val) == None:
				d[val] = 1
			else:
				d[val] += 1
	ans = 0
	for i in d:
		m = k * (d[i] - 1) + i + 1
		ans = max(ans, m)
	print(ans)


t = int(input())
for ii in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	diffMap = {}
	for i in a:
		r = i % k
		if r == 0:
			continue
		r = k - r
		if r in diffMap:
			diffMap[r] += 1
		else:
			diffMap[r] = 1
	l = list(diffMap.keys())
	l.sort()
	maxVal = 0
	for i in l:
		num = diffMap[i]
		temp = k * num - (k - i)
		if temp > maxVal:
			maxVal = temp
	if maxVal > 0:
		print(maxVal + 1)
	else:
		print(maxVal)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, Counter
import math

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
t = intIn()
while t > 0:
	t -= 1
	(n, k) = listIn()
	arr = listIn()
	li = arr
	cnt = 0
	for i in range(n):
		li[i] = arr[i] % k
		if li[i] == 0:
			cnt += 1
	if cnt == n:
		print(0)
	else:
		for i in range(n):
			li[i] = k - li[i]
		di = defaultdict(int)
		li2 = li
		for i in range(n):
			di[li[i]] += 1
			li2[i] += (di[li[i]] - 1) * k
		for i in range(n):
			if li2[i] % k == 0:
				li2[i] = 0
		ans = max(li2)
		print(ans + 1)


def solve(n, k, a):
	rem = {}
	for x in a:
		d = x % k
		if d != 0:
			rem[d] = rem.get(d, 0) + 1
	sol = 0
	for (d, f) in rem.items():
		c = f * k - d
		sol = max(sol, c)
	return sol + int(sol > 0)
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	print(solve(n, k, a))


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


def array_converter(k, numbers):
	numbers = [(number, k - number % k) for number in numbers if number % k]
	if not len(numbers):
		return 0
	requirements = dict()
	number_dict = dict()
	for (number, requirement) in numbers:
		requirements[requirement] = requirements.get(requirement, -1) + 1
		number_dict[requirement + k * requirements[requirement]] = number
	return max(number_dict.keys()) + 1
test_cases = int(input())
while test_cases:
	(n, k) = map(int, input().split())
	print(array_converter(k, list(map(int, input().split()))))
	test_cases -= 1


from collections import defaultdict
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = defaultdict(int)
	for i in a:
		if i % k == 0:
			continue
		s[i % k] += 1
	cnt = 0
	for i in s:
		cnt = max(cnt, s[i] * k - i)
	print(cnt + 1 if cnt != 0 else 0)


def f(k, arr):
	a_m_dict = {}
	for a in arr:
		m = a % k
		if m:
			a_m_dict[k - m] = a_m_dict.get(k - m, 0) + 1
	if not a_m_dict:
		return 0
	result = 0
	for (key, v) in a_m_dict.items():
		result = max(result, key + (v - 1) * k)
	return result + 1
t = int(input())
for _ in range(t):
	(n, k) = tuple(map(int, input().split()))
	arr = list(map(int, input().split()))
	print(f(k, arr))


from collections import defaultdict
for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l1 = []
	l.sort()
	for i in range(len(l)):
		if l[i] % k == 0:
			l1.append(0)
		else:
			l1.append((l[i] // k + 1) * k - l[i])
	l1.sort()
	d = defaultdict(int)
	tmp = 0
	d[l1[0]] = l1[0]
	for i in range(1, len(l)):
		if l1[i] == 0:
			continue
		if l1[i - 1] == l1[i] or d[l1[i]] != 0:
			l1[i] = l1[i - 1] + k
		else:
			d[l1[i]] = l1[i]
	ans = 0
	l1.sort()
	x = 0
	for i in range(len(l1)):
		if l1[i] == 0:
			continue
		else:
			ans += l1[i] - x
			ans += 1
			x = l1[i] + 1
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	data = map(int, input().split())
	abcd = dict()
	for j in data:
		r = j % k
		if r in abcd:
			abcd[r] += 1
		else:
			abcd[r] = 1
	finalist = list()
	for j in abcd:
		if j == 0:
			finalist.append(0)
		else:
			finalist.append(k - j + (abcd[j] - 1) * k)
	if max(finalist) == 0:
		print(0)
	else:
		print(max(finalist) + 1)


def solve():
	(n, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	lst2 = [lst[i] % k for i in range(n)]
	lst2.sort()
	lastelem = -1
	colvo = 0
	mxcolvo = 0
	mxnum = 0
	for i in lst2:
		if i == 0:
			continue
		if lastelem == i:
			colvo += 1
		else:
			if mxcolvo == colvo:
				mxnum = max((mxnum, (k - lastelem) % k))
			if mxcolvo < colvo:
				mxcolvo = colvo
				mxnum = (k - lastelem) % k
			colvo = 1
		lastelem = i
	if mxcolvo == colvo:
		mxnum = max(mxnum, (k - lastelem) % k)
	if mxcolvo < colvo:
		mxcolvo = colvo
		mxnum = (k - lastelem) % k
	print(max(mxcolvo * k - k + mxnum + 1, 0))
for i in range(int(input())):
	solve()


import os
import sys
from io import BytesIO, IOBase
from bisect import bisect_left, bisect_right
import threading
from collections import Counter, defaultdict
arr = []

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		arr = list(map(int, input().split()))
		m_a = [k - i % k for i in arr if i % k != 0]
		c = Counter(m_a)
		ans = 0
		for (i, j) in c.items():
			ans = max(ans, (j - 1) * k + i)
		if len(m_a) == 0:
			ans = -1
		print(ans + 1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from math import *
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split(' ')))
	li = list(map(int, input().split(' ')))
	res = []
	for x in li:
		temp = int(ceil(x / k))
		res.append(k * temp - x)
	temp = set(res)
	ans = 0
	count = {}
	for x in temp:
		count[x] = 0
	for x in res:
		if x == 0:
			continue
		count[x] += 1
	for x in temp:
		t1 = x + (count[x] - 1) * k + 1
		ans = max(ans, t1)
	print(ans)


from collections import defaultdict
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = [int(i) for i in input().split()][:n]
	d = defaultdict(int)
	ans = 0
	for i in l:
		if i % k != 0:
			rem = k - i % k
			if d[rem] == 0:
				d[rem] = rem
			else:
				d[rem] += k
			ans = max(ans, d[rem])
	if ans == 0:
		print(0)
	else:
		print(ans + 1)


from sys import stdin
input = lambda : stdin.readline().strip()
char = [chr(i) for i in range(97, 123)]
CHAR = [chr(i) for i in range(65, 91)]
mp = lambda : list(map(int, input().split()))
INT = lambda : int(input())
rn = lambda : range(INT())
from math import ceil, sqrt, factorial, gcd
for _ in rn():
	(n, k) = mp()
	l = mp()
	x = 0
	h = {}
	for i in l:
		if i % k != 0:
			m = k - i % k
			if m in h:
				h[m] += 1
			else:
				h[m] = 1
	ans = []
	for i in h:
		if h[i] == 1:
			ans.append(i)
		else:
			m2 = i + k * (h[i] - 1)
			ans.append(m2)
	if len(ans) == 0:
		print(0)
	else:
		print(max(ans) + 1)


T = int(input().rstrip())
for tt in range(T):
	(n, k) = list(map(int, input().rstrip().split(' ')))
	arr = list(map(int, input().rstrip().split(' ')))
	hsh = {}
	for i in arr:
		val = i % k
		if val != 0:
			hsh[val] = hsh.get(val, 0) + 1
	if len(hsh) == 0:
		print(0)
		continue
	mx2 = -1
	for mx in hsh:
		val2 = k - mx
		cnt = hsh[mx] - 1
		val3 = val2 + k * cnt + 1
		if val3 > mx2:
			mx2 = val3
	print(mx2)


def solution(arr, k):
	r = [i % k for i in arr]
	d = {}
	for i in r:
		d[i] = d.get(i, 0) + 1
	e = []
	for i in d:
		if i > 0:
			e.append(d[i])
	if len(e) == 0:
		return 0
	val = max(e)
	f = []
	for i in d:
		if d[i] == val and i > 0:
			f.append(i)
	return val * k - min(f) + 1
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	print(solution(arr, k))


from collections import defaultdict
for _ in range(int(input())):
	s = list(map(int, input().split(' ')))
	n = s[0]
	k = s[1]
	arr = list(map(int, input().split(' ')))
	x = 0
	arr2 = defaultdict(int)
	for i in range(n):
		arr2[k - arr[i] % k] += 1
	r = 0
	for (i, j) in arr2.items():
		if i != k:
			r = max(r, i + k * (j - 1))
	if arr2[k] == n:
		print(0)
	else:
		print(r + 1)


from sys import stdin, stdout
from collections import defaultdict
test = int(stdin.readline())
for _ in range(test):
	(n, k) = map(int, stdin.readline().split())
	cnt = defaultdict(int)
	A = [int(x) for x in stdin.readline().split()]
	for i in A:
		if i % k:
			cnt[k - i % k] += 1
	if len(cnt) == 0:
		print(0)
		continue
	done = k - len(cnt) - 1
	cnt[0] = 0
	op = 1
	x = 1
	lst = [(v, k) for (k, v) in cnt.items()]
	lst.sort()
	ind = lst[-1][1]
	maxx = lst[-1][0]
	op = k * (maxx - 1) + 1 + ind
	print(op)


import math
from sys import stdin
from collections import Counter, defaultdict, deque
input = stdin.readline
mod = pow(10, 9) + 7

def solve():
	(n, k) = map(int, input().split())
	l1 = list(map(int, input().split()))
	for i in range(n):
		l1[i] = k - l1[i] % k
	d = defaultdict(int)
	for i in range(n):
		d[l1[i]] += 1
	max1 = -1
	for (c1, c2) in d.items():
		if c1 != k:
			if c2 > max1:
				max1 = c2
				max2 = c1
			elif c2 == max1 and c1 > max2:
				max2 = c1
	if max1 == -1:
		print(0)
	else:
		v = max1 * k - (k - max2)
		print(v + 1)
for _ in range(int(input())):
	solve()


t = int(input())
for ts in range(t):
	(l, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	f = {}
	fm = 0
	fr = 0
	for i in a:
		if i % k != 0:
			f[i % k] = f.get(i % k, 0) + 1
			if f[i % k] > fm or (f[i % k] == fm and i % k < fr):
				fm = f[i % k]
				fr = i % k
	if fr == 0:
		print(0)
	else:
		print(1 + (k - fr) % k + (fm - 1) * k)


from collections import Counter

def f(n, k, l):
	c = Counter()
	best = [0, 0]
	for x in l:
		m = (k - x) % k
		if m != 0:
			c[m] += 1
			if c[m] > best[0] or (c[m] == best[0] and m > best[1]):
				best = [c[m], m]
	if best[0] == 0:
		return 0
	return best[1] + (best[0] - 1) * k + 1
numberofcases = int(input())
for _ in range(numberofcases):
	(n, k) = [int(t) for t in input().split()]
	l = [int(t) for t in input().split()]
	print(f(n, k, l))


from sys import stdin, stdout

def max(x, y):
	if x > y:
		return x
	return y

def getints():
	return map(int, stdin.readline().strip().split())

def getlist():
	return list(getints())
t = stdin.readline().strip()
t = int(t)
n = 0
k = 0

def comp(x):
	return x % k
while t > 0:
	t -= 1
	(n, k) = getints()
	ans = 0
	a = getlist()
	a.sort(key=comp)
	i = 0
	while i < n:
		if i < n:
			if a[i] % k == 0:
				i += 1
				continue
		for j in range(i, n + 1):
			if j == n:
				break
			if a[j] % k != a[i] % k:
				break
		l = j - i
		m = a[i] % k
		s = (l - 1) * k + (k - a[i] % k) % k
		ans = max(ans, s + 1)
		i = j
	print(ans)


def main():
	t = int(input())
	for _ in range(t):
		(x, y) = input().split()
		x = int(x)
		y = int(y)
		z = list(map(int, input().split()))
		dict = {g % y: 0 for g in set(z)}
		maxi = 0
		for g in z:
			if g % y != 0:
				dict[g % y] += y - g % y if dict[g % y] == 0 else y
				maxi = dict[g % y] if dict[g % y] > maxi else maxi
		print(maxi + 1 if maxi != 0 else 0)
main()


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def main():
	t = I()
	rr = []
	for _ in range(t):
		(n, k) = LI()
		a = LI()
		c = collections.defaultdict(int)
		for b in a:
			c[(k - b) % k] += 1
		t = (0, 0)
		for (kk, v) in c.items():
			if kk == 0:
				continue
			u = (v, kk)
			if t < u:
				t = u
		if t == (0, 0):
			rr.append(0)
		else:
			rr.append((t[0] - 1) * k + t[1] + 1)
	return JA(rr, '\n')
print(main())


from collections import Counter
from collections import defaultdict
from collections import deque
import math
import heapq
import sys
import io, os
input = sys.stdin.readline
from bisect import *
rs = lambda : input().strip()
ri = lambda : int(input())
rl = lambda : list(map(int, input().strip().split()))
rls = lambda : list(map(str, input().split()))
t = int(input())
for _ in range(0, t):
	(n, k) = rl()
	a = rl()
	ans = []
	for i in range(0, n):
		if a[i] % k != 0:
			ans.append(k - a[i] % k)
	if len(ans) == 0:
		print(0)
		continue
	d = Counter(ans)
	mx = -1
	q = 0
	for (i, j) in d.items():
		if j > mx:
			mx = j
			key = i
		elif j == mx:
			if i > key:
				key = i
	ans = (mx - 1) * k
	ans = ans + key + 1
	print(ans)


def increment(umap, x):
	try:
		umap[x] += 1
	except:
		umap[x] = 1

def solve():
	(n, k) = map(int, input().strip().split())
	a = list(map(int, input().strip().split()))
	umap = {}
	maxVal = 0
	maxBy = 0
	for i in a:
		rem = -i % k
		increment(umap, rem)
		if umap[rem] > maxVal and rem != 0:
			maxVal = umap[rem]
			maxBy = rem
		elif umap[rem] == maxVal and rem > maxBy:
			maxBy = rem
	if maxBy == 0:
		ans = 0
	else:
		ans = (maxVal - 1) * k + maxBy + 1
	print(ans)
t = int(input().strip())
for _ in range(t):
	solve()


import os
import sys
from io import BytesIO, IOBase
from collections import Counter, defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919]
from math import ceil

def lmii():
	return list(map(int, input().split()))
t = int(input())
for i in range(t):
	(n, k) = lmii()
	nums = lmii()
	d = defaultdict(int)
	for i in nums:
		if i % k == 0:
			continue
		d[i % k] += 1
	ans = 0
	for i in d:
		ans = max(ans, k * d[i] - i + 1)
	print(ans)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	dec = []
	for a in arr:
		rem = a % k
		if rem != 0:
			dec.append(k - rem)
	dec.sort()
	ans = 0
	i = 0
	dn = len(dec)
	if dn != 0:
		ans = 1
	while i < dn:
		cur = dec[i]
		rep = 0
		while i < dn and cur == dec[i]:
			rep += 1
			i += 1
		ans = max((rep - 1) * k + cur, ans)
	if dn != 0:
		ans += 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	dic = {}
	for ele in arr:
		if ele % k:
			key = k - ele % k
			dic[key] = dic.get(key, 0) + 1
	maxi = 0
	for (key, value) in dic.items():
		val = key + 1 + (value - 1) * k
		maxi = max(maxi, val)
	print(maxi)


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		(n, k) = In()
		l = list(In())
		rem = []
		for x in range(n):
			z = math.ceil(l[x] / k) * k - l[x]
			if z:
				rem.append(z)
		if len(rem):
			rem.sort()
			i = 0
			n1 = len(rem)
			while i < n1:
				x = 1
				q = 1
				for j in range(i + 1, n1):
					if rem[j] != rem[i]:
						i = j
						q = 0
						break
					else:
						rem[j] += k * x
						x += 1
				if q:
					break
			rem.sort()
			ans = rem[0] + 1
			j = rem[0] + 1
			for x in range(1, n1):
				ans += rem[x] - j
				ans += 1
				j = rem[x] + 1
			print(ans)
		else:
			print(0)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


for _ in range(int(input())):
	liStr = input().split()
	n = int(liStr[0])
	k = int(liStr[1])
	liStr = input().split()
	arr = []
	for i in liStr:
		arr.append(int(i))
	remArr = []
	toAdd = []
	for i in arr:
		remArr.append(i % k)
	for i in remArr:
		if i == k or i == 0:
			continue
		toAdd.append(k - i)
	if len(toAdd) == 0:
		print('0')
		continue
	di = {}
	for i in toAdd:
		di[i] = di.get(i, 0) + 1
	mf = -1
	me = 0
	for i in di:
		e = i
		f = di[i]
		if f > mf:
			mf = f
			me = e
		if f == mf and e > me:
			me = e
	print((mf - 1) * k + me + 1)


import sys
import math
import collections

def set_debug(debug_mode=False):
	if debug_mode:
		fin = open('input.txt', 'r')
		sys.stdin = fin

def int_input():
	return list(map(int, input().split()))
t = int(input())
for ti in range(1, t + 1):
	(n, k) = int_input()
	A = int_input()
	seen = set()
	d = collections.defaultdict(int)
	total = 0
	for x in A:
		m = x % k
		if m != 0:
			d[k - m] += 1
			total += 1
			seen.add(k - m)
	if total == 0:
		print(0)
		continue
	seen = sorted(list(seen))
	total -= 1
	d[seen[0]] -= 1
	last = seen[0]
	res = seen[0]
	pos = 1 % len(seen)
	while total > 0:
		cur = seen[pos]
		if d[cur] > 0:
			total -= 1
			d[cur] -= 1
		res += cur - last if cur - last > 0 else cur - last + k
		last = cur
		pos = (pos + 1) % len(seen)
	print(res + 1)


import math
from collections import Counter
tt = int(input())
for _ in range(0, tt):
	(n, k) = map(int, input().split())
	a = [int(i) % k for i in input().split()]
	cha = [k - int(i) for i in a if i]
	cde = Counter(cha)
	asw = 0
	for i in cde:
		asw = max(asw, i + k * (cde[i] - 1))
	if asw == 0:
		print(asw)
	else:
		print(asw + 1)


import sys
from sys import stdin
from math import factorial
from collections import Counter

def neo():
	return map(int, input().split())

def Neo():
	return list(map(int, input().split()))
for _ in range(int(input())):
	(n, x) = neo()
	A = Neo()
	B = []
	for i in range(n):
		if A[i] % x != 0:
			B.append(x - A[i] % x)
	if len(B) == 0:
		print(0)
	else:
		Z = Counter(B)
		t = max(Z.values())
		q = 0
		for i in Z:
			if Z[i] == t:
				q = max(i + 1, q)
		print(x * (t - 1) + q)


from collections import defaultdict
import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	arr = []
	for i in range(n):
		if lst[i] % k:
			arr.append(k - lst[i] % k)
	d = defaultdict(int)
	for i in arr:
		d[i] += 1
	if len(arr) == 0:
		print(0)
	else:
		a = 0
		b = 0
		for (i, v) in d.items():
			if a < v:
				a = v
				b = i
			elif a == v:
				b = max(b, i)
		print(b + 1 + (a - 1) * k)


from collections import Counter

def ans(n, k, arr):
	if all([d % k == 0 for d in arr]):
		return 0
	c = Counter(arr)
	m = max(c.values())
	vals = max([x for x in c.keys() if c[x] == m])
	return k * (m - 1) + vals + 1
t = int(input())
L = []
for i in range(t):
	(n, k) = map(int, input().split())
	arr = [(k - int(x) % k) % k for x in input().split() if (k - int(x) % k) % k != 0]
	L.append(ans(n, k, arr))
for l in L:
	print(l)


from collections import defaultdict as dd
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	g = dd(int)
	ans = 0
	for i in map(int, input().split()):
		if i % k:
			g[k - i % k] += 1
	x = 0
	for i in g:
		ans = max(ans, i + k * (g[i] - 1) + 1)
	print(ans)


t = int(input())
for T in range(t):
	(n, k) = [int(i) for i in input().split()]
	array = [int(i) for i in input().split()]
	array_modk = [(k - i) % k for i in array]
	sums = {i: 0 for i in array_modk}
	for i in array_modk:
		if i != 0:
			sums[i] += 1
	maxi = max(sums.values())
	candidates = []
	for i in sums:
		if sums[i] == maxi:
			candidates.append(i)
	maxicnd = max(candidates)
	print(max((maxi - 1) * k + maxicnd + 1, 0))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	mod = []
	for num in a:
		if num % k != 0:
			rem = (num // k + 1) * k - num
			mod.append(rem)
	if len(mod) == 0:
		print(0)
		continue
	have_seen = dict()
	ans = 0
	for rem in mod:
		if rem not in have_seen:
			ans = max(rem, ans)
			have_seen[rem] = rem
		else:
			new_rem = have_seen[rem] + k
			ans = max(ans, new_rem)
			have_seen[rem] = new_rem
	ans += 1
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	inp = [int(j) for j in input().split()]
	dict = {}
	cnt = 0
	answer = 0
	for i in range(len(inp)):
		if inp[i] % k == 0:
			cnt = cnt + 1
		else:
			temp = k - inp[i] % k
			if temp in dict:
				dict[temp] = dict[temp] + 1
				ans = k * (dict[temp] - 1) + temp
				answer = max(ans, answer)
			else:
				dict[temp] = 1
				ans = k * (dict[temp] - 1) + temp
				answer = max(ans, answer)
	if cnt == n:
		print(0)
	else:
		print(answer + 1)


import sys

def func(t, k):
	for i in range(0, sys.maxsize, k):
		if i >= t:
			break
	return i
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	mp = dict()
	temp = map(int, input().split())
	for i in temp:
		if func(i, k) - i not in mp:
			mp[func(i, k) - i] = 0
		mp[func(i, k) - i] += 1
	ans = 0
	for i in mp.keys():
		if i != 0:
			temp = i + (mp[i] - 1) * k
			ans = max(ans, temp)
	if ans == 0:
		print(0)
	else:
		print(ans + 1)


from collections import Counter
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr = [ele % k for ele in arr]
	counter = Counter(arr)
	items = sorted(counter.items(), key=lambda x: (x[1], -x[0]))
	(last, freq) = items.pop()
	flag = True
	if last % k == 0:
		if items:
			(last, freq) = items.pop()
		else:
			flag = False
	if flag:
		ans = last * (freq - 1) + freq * (k - last) + 1
		print(ans)
	else:
		print(0)


import math
import os
import random
import re
import sys
import heapq
import random
t = int(input())
while t > 0:
	t -= 1
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	counts = {}
	for a in arr:
		a = a % k
		if a == 0:
			continue
		if a in counts:
			counts[a] += 1
		else:
			counts[a] = 1
	highest = -1
	selc = -1
	ans = -1
	for c in counts:
		if counts[c] > highest or (counts[c] == highest and c < selc):
			highest = counts[c]
			selc = c
			ans = counts[c] * k - c + 1
	print(ans if ans > -1 else 0)


from sys import stdin, stdout
input = stdin.readline

def solve(cs):
	(n, m) = map(int, input().split())
	v = list(map(int, input().split()))
	mp = dict()
	for x in v:
		x %= m
		if x == 0:
			continue
		if mp.__contains__(m - x):
			mp[m - x] += 1
		else:
			mp[m - x] = 1
	ans = 0
	for x in mp:
		ans = max(ans, (mp[x] - 1) * m + x + 1)
	print(ans)
for tc in range(int(input())):
	solve(tc + 1)


import sys
from collections import defaultdict
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		c = defaultdict(lambda : 0)
		for x in a:
			c[(k - x % k) % k] += 1
		ans = 0
		for (key, val) in c.items():
			if key > 0:
				ans = max(ans, key + (val - 1) * k)
		if ans == 0:
			print(0)
		else:
			print(ans + 1)
main()


def getKeysByValue(dictOfElements, valueToFind):
	listOfKeys = list()
	listOfItems = dictOfElements.items()
	for item in listOfItems:
		if item[1] == valueToFind:
			listOfKeys.append(item[0])
	return listOfKeys
t = int(input())
ans = []
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	a = list(map(int, input().split()))
	b = []
	to = 0
	x = 0
	mpp = {}
	for j in range(n):
		if a[j] % k == 0:
			continue
		else:
			b.append(k - a[j] % k)
			if k - a[j] % k not in mpp.keys():
				mpp[k - a[j] % k] = 1
				to += 1
			else:
				mpp[k - a[j] % k] += 1
				to += 1
	c = list(mpp.values())
	if len(c) != 0:
		maxx = max(c)
		ke = getKeysByValue(mpp, maxx)
		keymax = max(ke)
		ans.append((maxx - 1) * k + (keymax + 1))
	else:
		ans.append(0)
for an in ans:
	print(an)


from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(lambda x: (k - int(x)) % k, input().split()))
	c = Counter(a)
	if 0 in c:
		c.pop(0)
	if len(c) == 0:
		print(0)
	else:
		most_mod = max(c, key=lambda x: (c[x], x))
		print(1 + (c[most_mod] - 1) * k + most_mod)


from collections import Counter

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		(x, o) = (1, 1)
		l = list(filter(lambda x: x % k != 0, map(lambda x: k - x % k, a)))
		r = set(l)
		i = 0
		n = len(l)
		d = dict(Counter(l))
		(maxi, maxikey) = (-1, -1)
		for i in d:
			if d[i] > maxi:
				maxi = d[i]
				maxikey = i
			elif d[i] == maxi and maxikey < i:
				maxikey = i
		print(maxikey + 1 + (maxi - 1) * k if maxi != -1 else 0)
main()


def f(ai, k):
	return (k - ai % k) % k
t = int(input())
for tt in range(t):
	(n, k) = [int(x) for x in input().split(' ')]
	a = [int(x) for x in input().split(' ')]
	returns = [0] * n
	for i in range(n):
		returns[i] = f(a[i], k)
	sall = set()
	da = {}
	for i in range(n):
		sall.add(returns[i])
	for x in sall:
		da[x] = 0
	for x in returns:
		da[x] += 1
	if 0 in da:
		del da[0]
	if len(da) == 0:
		print(0)
		continue
	cont_max = 0
	for x in da.values():
		cont_max = max(cont_max, x)
	anss = 0
	for x in da:
		if da[x] == cont_max:
			anss = max(anss, x)
	print(cont_max * k - k + anss + 1)


from collections import Counter
t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	a = Counter((k - int(i) % k for i in input().split() if int(i) % k))
	print(max((i + (a[i] - 1) * k + 1 for i in a)) if a else '0')


from collections import defaultdict
for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	a = [(k - int(i) % k) % k for i in input().split()]
	b = defaultdict(lambda : 0)
	total = 0
	for i in a:
		if i != 0:
			b[i] += 1
			total += 1
	if total > 0:
		maxi = max(list(b.values()))
		ind = -1
		for i in b:
			if b[i] == maxi:
				if i > ind:
					ind = i
		count = 0
		count += ind
		count += (maxi - 1) * k
		print(count + 1)
	else:
		print(0)


def answer(n, k, A):
	d = {}
	maxi = 0
	index = 0
	for i in range(n):
		key = k - A[i] % k
		if key != k:
			if key in d:
				d[key] += 1
				if d[key] > maxi:
					maxi = d[key]
					index = key
				elif d[key] == maxi and key > index:
					index = key
			else:
				d[key] = 1
				if d[key] > maxi:
					maxi = d[key]
					index = key
				elif d[key] == maxi and key > index:
					index = key
	if maxi == 0:
		return 0
	return (maxi - 1) * k + index + 1
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	print(answer(n, k, A))


from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [*map(int, input().split())]
	if all((i % k == 0 for i in a)):
		print(0)
		continue
	a = [k - i % k if i % k > 0 else 0 for i in a]
	a = Counter(a)
	ans = 0
	for (i, j) in a.items():
		if i == 0:
			continue
		ans = max(ans, i + k * (j - 1) + 1)
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	for i in range(n):
		if a[i] % k != 0:
			x = k - a[i] % k
			if x not in d:
				d[x] = 1
			else:
				d[x] += 1
	ans = 0
	if not d:
		print(0)
		continue
	for x in d:
		ans = max(ans, x + (d[x] - 1) * k)
	print(ans + 1)


import sys
from collections import Counter as CO
input = sys.stdin.readline
from collections import defaultdict as dd
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	for i in range(n):
		arr[i] %= k
	freq = dict(CO(arr))
	maxf = 0
	maxval = 99999999999999
	for j in freq:
		if j != 0:
			if freq[j] > maxf:
				maxf = freq[j]
				maxval = j
			elif freq[j] == maxf:
				if maxval > j:
					maxval = j
	if maxf == 0:
		print(0)
	else:
		print((maxf - 1) * k + (k - maxval + 1))


import sys
from collections import Counter

def swap(x, y, a):
	temp = a[x]
	a[x] = a[y]
	a[y] = temp
	return a

def solve():
	return None

def main():
	q = []
	for line in sys.stdin.readlines():
		q.append(line)
	for i in range(len(q)):
		q[i] = q[i].rstrip().split(' ')
		q[i] = [int(x) for x in q[i]]
	for i in range(1, len(q), 2):
		k = q[i][1]
		a = q[i + 1]
		mod = Counter()
		for i in a:
			if i % k != 0:
				mod[k - i % k] += 1
		if len(mod) == 0:
			print(0)
			continue
		val = max(list(mod.values()))
		keys = list(mod.keys())
		max_key = 0
		for i in keys:
			if mod[i] == val and i > max_key:
				max_key = i
		print((mod[max_key] - 1) * k + max_key % k + 1)
main()


import sys
input = sys.stdin.readline
from collections import Counter as cc
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(n, k) = I()
	l = I()
	l = [i % k for i in l]
	p = cc(l)
	f = max(l, key=lambda x: [p[x], -x] if x != 0 else [-1, 1])
	ct = p[f]
	r = abs(f - k)
	print(k * (ct - 1) + r + 1 if f != 0 else 0)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = dict()
	d[0] = 0
	for i in a:
		v = (k - i) % k
		if v:
			if v not in d:
				d[v] = v + 1
			else:
				d[v] += k
	print(max(d.values()))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	for i in range(n):
		if a[i] % k != 0:
			if a[i] % k not in d:
				d[a[i] % k] = 1
			else:
				d[a[i] % k] += 1
	m = 0
	val = k
	for i in d:
		if m < d[i]:
			m = d[i]
			val = i
		elif m == d[i]:
			if val > i and i != 0:
				val = i
	if m == 0:
		print(0)
	else:
		print((m - 1) * k + k - val + 1)


T = int(input())
for t in range(T):
	(n, k) = (int(i) for i in input().split())
	last = {}
	maxx = 0
	for i in input().split():
		a = int(i)
		if a > k:
			if a % k == 0:
				x = a
			else:
				x = (a // k + 1) * k
		else:
			x = k
		y = x - a
		if y not in last or y == 0:
			last[y] = y
		else:
			last[y] += k
		if maxx < last[y]:
			maxx = last[y]
	if maxx == 0:
		print(0)
	else:
		print(maxx + 1)


T = int(input())
for tc in range(T):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = dict()
	mc = 0
	mn = 0
	for i in range(len(a)):
		a[i] = k - a[i] % k
		if a[i] != k:
			if not d.get(a[i]):
				d[a[i]] = 1
				if mc == 0:
					mc = 1
					mn = a[i]
				elif mc == 1 and mn < a[i]:
					mn = a[i]
			else:
				d[a[i]] += 1
				if mc < d[a[i]]:
					mc = d[a[i]]
					mn = a[i]
				elif mc == d[a[i]] and mn < a[i]:
					mn = a[i]
	if mn == mc == 0:
		print(0)
	else:
		print(mn + k * (mc - 1) + 1)


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	a = [k - int(x) % k for x in input().split()]
	checker = dict()
	for i in a:
		if i == k:
			continue
		if i not in checker:
			checker[i] = 0
		checker[i] += 1
	bestVal = 0
	bestAdd = 0
	for i in checker:
		if checker[i] > bestVal:
			bestVal = checker[i]
			bestAdd = i
		elif checker[i] == bestVal:
			bestAdd = max(bestAdd, i)
	ans = k * (bestVal - 1) + bestAdd + 1
	if ans < 0:
		ans = 0
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	final = []
	for i in a:
		if i % k != 0:
			final.append(i)
	if len(final) == 0:
		print(0)
	else:
		h = k
		new_arr = []
		d = dict()
		track = dict()
		for i in final:
			if d.get(i) == None:
				if i < k:
					d[i] = k - i
					track[k - i] = 0
				else:
					k = h * (i // h + 1)
					d[i] = k - i
					track[k - i] = 0
		for i in final:
			new_arr.append(d[i])
		for i in range(len(new_arr)):
			if track[new_arr[i]] == 0:
				track[new_arr[i]] = new_arr[i]
			else:
				track[new_arr[i]] = track[new_arr[i]] + h
		res = []
		for i in track:
			res.append(track[i])
		print(max(res) + 1)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	rem = {}
	for j in range(len(l)):
		if l[j] % k == 0:
			continue
		elif l[j] % k in rem:
			rem[l[j] % k] += 1
		else:
			rem[l[j] % k] = 1
	count = 0
	for j in rem:
		count = max(count, rem[j] * k - j + 1)
	print(count)


a = int(input())
for i in range(0, a):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	rem = []
	for i in arr:
		if not i % k == 0:
			rem.append(k - i % k)
	srem = set()
	rem.sort()
	d = dict()
	for i in rem:
		d[i] = 1
	for i in rem:
		if i in srem:
			srem.add(i + d[i] * k)
			d[i] = d[i] + 1
		else:
			srem.add(i)
	rem = []
	for i in srem:
		rem.append(i)
	rem.sort()
	ans = 0
	if len(rem) > 0:
		ans = rem[0]
	for i in range(1, len(rem)):
		ans = ans + rem[i] - rem[i - 1]
	if len(rem) == 0:
		print(0)
	else:
		print(ans + 1)


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def modefiedSieve():
	mx = 2750132
	sieve = [-1] * mx
	for i in range(2, mx):
		if sieve[i] == -1:
			sieve[i] = i
			for j in range(i * i, mx, i):
				if sieve[j] == -1:
					sieve[j] = i
	return sieve

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	maxint = 10 ** 10
	max_so_far = -maxint - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def solve():
	(n, k) = num_input()
	visited = [False] * n
	arr = list_input()
	temp = {}
	x = set()
	for i in arr:
		if i % k != 0:
			ans = k - i % k
			try:
				temp[ans] += 1
			except KeyError:
				temp[ans] = 0
			x.add(ans + k * temp[ans])
	arr = list(x)
	if len(arr) == 0:
		print(0)
		return
	print(max(arr) + 1)
t = 1
t = int(input())
for _ in range(t):
	solve()


from collections import deque
T = int(input())
while T:
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	R = []
	for i in range(n):
		r = k - A[i] % k
		if r != k:
			R.append(r)
	m = len(R)
	D = {}
	for i in range(m):
		if R[i] in D:
			z = R[i]
			R[i] = z + D[z]
			D[z] = D[z] + k
			D[R[i]] = k
		else:
			D[R[i]] = k
	R.sort()
	if len(R) == 0:
		print(0)
	else:
		print(max(R) + 1)
	T = T - 1


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
for ii in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	need = defaultdict(int)
	ans = -1
	for i in arr:
		if i % k != 0:
			need[i % k] += 1
	for i in need:
		temp = k - i
		temp += (need[i] - 1) * k
		ans = max(temp, ans)
	ans += 1
	print(ans)


import sys
from collections import Counter

def rl():
	return sys.stdin.readline().strip()
T = int(rl())
for test in range(T):
	(n, k) = map(int, rl().split())
	arr = [int(x) % k for x in rl().split()]
	c = Counter(arr)
	c.pop(0, None)
	if c:
		c = sorted(c.items(), key=lambda x: x[0])
		c = sorted(c, key=lambda x: x[1], reverse=True)
		mcmod = c[0][0]
		mcfreq = c[0][1]
		print(k * (mcfreq - 1) + k + 1 - mcmod)
	else:
		print(0)


from collections import Counter
for _ in range(int(input().strip())):
	(n, k) = map(int, input().strip().split())
	a = Counter([int(x) % k for x in input().strip().split()])
	ans = [0]
	for key in a:
		if key != 0:
			ans.append(a[key] * k - key + 1)
	print(max(ans))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		if a[i] % k != 0:
			a[i] = k - a[i] % k
		else:
			a[i] = 0
	if a.count(0) == n:
		print(0)
		continue
	a.sort()
	v = {}
	maxi = 0
	for i in a:
		if i == 0:
			continue
		if i not in v.keys():
			v[i] = i
		else:
			v[i] += k
		maxi = max(0, v[i])
	print(max(v.values()) + 1)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	for i in range(n):
		if a[i] % k not in d:
			d[a[i] % k] = 1
		else:
			d[a[i] % k] += 1
	mx = 0
	for i in d.keys():
		if i != 0:
			mx = max(mx, k * d[i] - i)
	if mx:
		mx += 1
	print(mx)


tcs = int(input())
for tc in range(tcs):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	ans = 0
	d = dict()
	x = 0
	for a in arr:
		if a % k != 0:
			c = k - a % k
			if c in d:
				d[c] += 1
			else:
				d[c] = 1
	max_k = max_v = 0
	for key in sorted(list(d.keys())):
		if d[key] >= max_v:
			max_v = d[key]
			max_k = key
	if max_k == 0:
		print(0)
	else:
		print(k * (max_v - 1) + max_k + 1)


import sys
input = sys.stdin.buffer.readline
from collections import Counter

def I():
	return list(map(int, input().split()))

def sieve(n):
	a = [1] * n
	for i in range(2, n):
		if a[i]:
			for j in range(i * i, n, i):
				a[j] = 0
	return a
for __ in range(int(input())):
	(n, k) = I()
	arr = I()
	need = set()
	new = [0] * n
	f = True
	for i in range(n):
		toadd = k - arr[i] % k
		if toadd == k:
			toadd = 0
		else:
			f = False
		new[i] = toadd
	c = Counter(new)
	ans = 0
	for val in c:
		if val == 0:
			continue
		ans = max(ans, (c[val] - 1) * k + val + 1)
	print(ans)


for nt in range(int(input())):
	(n, k) = map(int, input().split())
	new = list(map(int, input().split()))
	a = []
	for i in range(n):
		if new[i] % k != 0:
			a.append(new[i])
	a.sort()
	n = len(a)
	if n == 0:
		print(0)
		continue
	d = {}
	maxx = 0
	for i in range(n):
		diff = k - a[i] % k
		if diff not in d:
			maxx = max(maxx, diff)
			d[diff] = 1
		else:
			maxx = max(maxx, d[diff] * k + diff)
			d[diff] += 1
	print(maxx + 1)


import math
t = int(input())
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	ma = -1
	d = {}
	for i in a:
		if i % k == 0:
			continue
		r = i % k
		r = k - r
		if r not in d:
			d[r] = 0
		d[r] += 1
		ma = max(ma, r + (d[r] - 1) * k)
	print(ma + 1)


import getopt
import sys
import math
onlyCase = -1
verbose = False
try:
	(opts, args) = getopt.getopt(sys.argv[1:], 'vc:', ['case='])
except getopt.GetoptError as err:
	print(str(err))
	sys.exit(2)
for (o, a) in opts:
	if o in ('-c', '--case'):
		onlyCase = int(a)
	elif o == '-v':
		verbose = True
	else:
		sys.exit()
ncases = int(input())
for c in range(1, ncases + 1):
	(n, k) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	if onlyCase != -1 and onlyCase != c:
		continue
	if verbose:
		print('[array %d to div %d]' % (n, k))
		print(arr)
	d = dict()
	for a in arr:
		r = k - a % k
		if r == k:
			continue
		if not r in d:
			d[r] = 1
		else:
			d[r] += 1
	if verbose:
		print(d)
	maxmoves = 0
	for (key, value) in d.items():
		mm = key + (value - 1) * k + 1
		if verbose:
			print('key: %d value %d : maxm %d' % (key, value, mm))
		if mm > maxmoves:
			maxmoves = mm
	print('%d' % maxmoves)


from collections import Counter
testn = int(input())
for i in range(testn):
	(length, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	diff_arr = map(lambda x: 0 if x % k == 0 else k - x % k, arr)
	count = Counter(diff_arr)
	max_rem = 0
	max_amount = 0
	for (rem, amount) in count.items():
		if rem != 0 and max_amount < amount or (max_amount == amount and max_rem < rem):
			max_amount = amount
			max_rem = rem
	if max_rem == 0:
		print(0)
	else:
		print((max_amount - 1) * k + max_rem + 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	for i in range(n):
		x = k - a[i] % k
		if x in d:
			d[x] += 1
		elif x < k:
			d[x] = 1
	cnt = 0
	key = 0
	for i in d:
		if d[i] >= cnt:
			cnt = d[i]
	for i in d:
		if cnt == d[i]:
			key = max(key, i)
	if len(d) == 0:
		print(0)
	else:
		print(key + 1 + (cnt - 1) * k)


from collections import Counter
for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(i) % k for i in input().split()][:n]
	a.sort()
	b = a.count(0)
	if b == len(a):
		print(0)
	else:
		zero = a.count(0)
		bb = a[zero:]
		f = [s for (l, s) in Counter(bb).items()]
		bbb = [l for (l, s) in Counter(bb).items()]
		c = max(f)
		oi = f.index(c)
		xx = bbb[oi]
		m = k * c
		g = m - (xx - 1)
		print(g)


for tt in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	d = dict()
	for i in arr:
		x = i % k
		if x != 0:
			if i % k in d:
				d[i % k] += 1
			else:
				d[i % k] = 1
	ans = 0
	for i in d.keys():
		ans = max(ans, d[i] * k - i)
	if ans != 0:
		print(ans + 1)
	else:
		print(0)


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	b = []
	for i in a:
		if i % k != 0:
			t = (i // k + 1) * k - i
			b.append(t)
	b.sort()
	ss = 0
	if len(b) > 0:
		t = b[0]
		cnt = 1
		for i in range(1, len(b)):
			if b[i] == t:
				cnt += 1
			else:
				if cnt >= ss:
					ss = cnt
					l = t
				cnt = 1
				t = b[i]
		if cnt >= ss:
			ss = cnt
			l = t
		print(k * (ss - 1) + l + 1)
	else:
		print(0)


def f():
	(n, k) = map(int, input().split())
	a = sorted([k - int(x) % k for x in input().split()])
	ind = n
	for i in range(n - 1, -1, -1):
		if a[i] == k:
			ind -= 1
	a = a[:ind]
	d = {}
	mx = 0
	if len(a) == 0:
		print(0)
		return
	for i in a:
		if i not in d.keys():
			d[i] = 1
		else:
			d[i] += 1
		if d[i] >= mx:
			mx = d[i]
			numb = i
	print(k * (mx - 1) + numb + 1)
t = int(input())
for i in range(t):
	f()


from collections import defaultdict

def read_list():
	return list(map(int, input().strip().split(' ')))

def print_list(l):
	print(' '.join(map(str, l)))

def judge_3(n):
	tmp = 0
	for c in str(n):
		tmp += int(c)
	return tmp % 3 == 0
N = int(input())
for _ in range(N):
	(n, k) = read_list()
	nums = read_list()
	dic = defaultdict(int)
	for n in nums:
		if n % k != 0:
			dic[k - n % k] += 1
	res = 0
	for key in dic:
		res = max(key + (dic[key] - 1) * k + 1, res)
	print(res)


from collections import Counter

def check(arr, k, n):
	for i in range(n):
		arr[i] = arr[i] % k
	d = Counter(arr)
	if 0 in d:
		del d[0]
	if not d:
		return 0
	m = 0
	p = max(arr)
	for i in d:
		if d[i] >= m:
			m = d[i]
	for i in d:
		if d[i] == m:
			if i < p:
				p = i
	return k * m - p + 1
t = int(input())
while t:
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	print(check(arr, k, n))
	t -= 1


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
for _ in range(inp()):
	(n, k) = inpl()
	a = inpl()
	d = defaultdict(int)
	for (i, x) in enumerate(a):
		if x % k == 0:
			continue
		d[(x // k + 1) * k - x] += 1
	res = 0
	for key in list(d):
		res = max(res, key + k * (d[key] - 1) + 1)
	print(res)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	dct = {}
	l = 0
	for i in arr:
		rem = i % k
		if rem != 0:
			if rem in dct:
				dct[rem] += 1
			else:
				l += 1
				dct[rem] = 1
	lst = list(dct.values())
	if len(lst) == 0:
		print(0)
		continue
	mx = max(lst)
	lst1 = list(dct.keys())
	ct = 0
	rem1 = 10 ** 9 + 7
	for i in range(l):
		if lst[i] == mx and lst1[i] < rem1:
			rem1 = lst1[i]
	sm = k - rem1
	sm += (k - 1) * (mx - 1) + mx
	print(sm)


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	(n, k) = map(int, sys.stdin.readline().split())
	list_num = list(map(int, sys.stdin.readline().split()))
	list_remainder = [k - num % k if num % k else 0 for num in list_num]
	dict_visit = {}
	ans = 0
	for num in list_remainder:
		if not num:
			continue
		if not num in dict_visit:
			dict_visit[num] = 1
			ans = max(ans, num + 1)
		else:
			ans = max(ans, dict_visit[num] * k + num + 1)
			dict_visit[num] += 1
	print(ans)


from collections import defaultdict
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split(' '))
	arr = list(map(int, input().split()))
	for i in range(n):
		arr[i] = arr[i] % k
	arr.sort(reverse=True)
	if arr[0] == 0:
		print(0)
		continue
	d = defaultdict(int)
	i = 0
	while i < n and arr[i] != 0:
		d[arr[i]] += 1
		i += 1
	seta = set(arr)
	if 0 in seta:
		seta.remove(0)
	m = max(d.values())
	mf = float('inf')
	for i in seta:
		if d[i] == m and i < mf:
			mf = i
	MOV = 1
	MOV += (m - 1) * k + (k - mf)
	print(MOV)


t = int(input())
for _ in range(0, t):
	(n, k) = list(map(int, input().split()))
	alist = list(map(int, input().split()))
	amax = 0
	cache = []
	for i in range(0, n):
		tmp = alist[i]
		if tmp % k == 0:
			cache.append(0)
			continue
		else:
			if tmp < k:
				b = k - tmp
			else:
				b = k - (tmp - k)
			if b < 0:
				b += k * abs(b // k)
			cache.append(b)
	cache.sort(reverse=True)
	if cache[0] == 0:
		print(0)
	else:
		cnt = 0
		now = 0
		bre = 1
		for i in range(0, len(cache)):
			if cache[now] != cache[i]:
				if cache[now] != 0:
					cnt = i - now - 1
					amax = max(amax, cache[now] + k * cnt)
				now = i
				bre = 0
		cnt = len(cache) - 1 - now
		if cache[now] != 0:
			amax = max(amax, cache[now] + k * cnt)
		print(amax + 1)


from collections import *
t = int(input())

def rem(x):
	return k - int(int(x) % k)
for i in range(t):
	(n, k) = list(map(int, input().split()))
	li = list(map(rem, input().split()))
	co = Counter(li)
	if k in co:
		co.pop(k)
	if len(co) == 0:
		print(0)
		continue
	ls = [max(co)]
	for i in co:
		x = co[i]
		if x > 1:
			ls += [(x - 1) * k + i]
	print(max(ls) + 1)


from collections import Counter

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		d = Counter()
		for v in a:
			r = v % k
			if r:
				r = k - r
			if r:
				d[r] += 1
		if not d:
			print(0)
			continue
		m = max(d.values())
		value = 0
		for v in d:
			if d[v] == m and v > value:
				value = v
		print(value + k * (m - 1) + 1)
main()


from sys import stdin
from collections import defaultdict
t = int(stdin.readline())
for _ in range(t):
	(n, k) = list(map(int, stdin.readline().rstrip().split(' ')))
	a = list(map(int, stdin.readline().rstrip().split(' ')))
	divArr = defaultdict(lambda : 0)
	for ai in a:
		if ai % k != 0:
			divArr[k - ai % k] += 1
	if len(divArr) == 0:
		print(0)
	else:
		numRound = max(divArr.values())
		idx = -1
		for (key, value) in divArr.items():
			if value == numRound and key > idx:
				idx = key
		answer = k * (numRound - 1)
		answer += idx + 1
		print(answer)


t = int(input())
for h in range(t):
	(n, k) = [int(i) for i in input().split(' ')]
	a = [int(i) for i in input().split(' ')]
	mod = {}
	for i in a:
		if i % k in mod:
			mod[i % k].append(i)
		else:
			mod[i % k] = [i]
	ans = 0
	m = 0
	for i in sorted(mod.keys()):
		if i == 0:
			continue
		if len(mod[i]) > ans:
			ans = len(mod[i])
			m = i
	if ans == 0:
		print(0)
	else:
		res = int(1)
		res += int((ans - 1) * k)
		res += int(k - m % k)
		print(res)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	x = 0
	a = list(map(lambda x: (k - x % k) * (x % k != 0), a))
	a.sort()
	c = 1
	d = a.copy()
	for j in range(n):
		if a[j] != 0:
			if j == 0:
				x = a[j]
			elif a[j] == a[j - 1]:
				d[j] = c * k + a[j]
				c = c + 1
			else:
				c = 1
	print(max(d) + 1 * (max(d) != 0))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = a[i] % k
	a.sort()
	blocks = [[a[0], 1]]
	for i in range(1, n):
		if a[i] == blocks[-1][0]:
			blocks[-1][1] += 1
		else:
			blocks += [[a[i], 1]]
	if blocks[0][0] == 0:
		blocks.pop(0)
	m = 0
	for i in blocks:
		m = max(m, i[1])
	for i in range(len(blocks) - 1, -1, -1):
		if blocks[i][1] == m:
			ind = i
	if m == 0:
		print(0)
		continue
	print((m - 1) * k + k - blocks[ind][0] + 1)


t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	l = list([int(x) for x in input().split()])
	d = dict()
	for i in range(n):
		l[i] = (k - l[i] % k) % k
		if l[i] in d and l[i] != 0:
			d[l[i]] += 1
		elif l[i] != 0:
			d[l[i]] = 1
	tl = []
	for i in d.keys():
		tl.append((d[i], i))
	tl.sort(reverse=True)
	if len(tl) == 0:
		print('0')
	else:
		print((tl[0][0] - 1) * k + tl[0][1] + 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	dic = {}
	c = 0
	for i in range(n):
		if arr[i] % k == 0:
			continue
		else:
			try:
				dic[arr[i] % k] += k
			except:
				dic[arr[i] % k] = k - arr[i] % k
	maxx = 0
	for i in dic:
		maxx = max(maxx, dic[i])
	if maxx > 0:
		print(maxx + 1)
	else:
		print(0)


t = int(input())
ans = []
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	b = [k - x % k for x in a if x % k != 0]
	if not b:
		ans.append(0)
	else:
		for el in b:
			d[el] = d.get(el, 0) + 1
		arr = []
		for el in d:
			arr.append(el + k * (d[el] - 1))
		ans.append(max(arr) + 1)
for el in ans:
	print(el)


def solution1():
	for tangocharlie in range(int(input())):
		(xx, yy, nn) = map(int, input().split())
		p = nn // xx
		k = p * xx + yy
		while k > nn:
			p -= 1
			k = p * xx + yy
		print(k)

def solution2():
	for tangocharlie in range(int(input())):
		nnn = int(input())
		apple = 5
		banana = 10
		orange = apple + banana
		answer = 0
		while nnn > 1:
			if nnn % 6 == 0:
				answer += 1
				nnn = nnn // 6
			elif nnn % 3 == 0 and nnn % 2 != 0:
				answer += 1
				nnn *= 2
			else:
				answer = -1
				break
		print(answer)

def solution3():
	for tangocharlie in range(int(input())):
		number = int(input())
		sunlight = list(input())
		opnn = wrong = 0
		for i in sunlight:
			if i == '(':
				opnn += 1
			else:
				opnn -= 1
			if opnn < 0:
				wrong += 1
				opnn = 0
		print(wrong)

def solution4():
	for tangocharlie in range(int(input())):
		(n, k) = map(int, input().split())
		abra_ka_dabra = sorted(list(map(int, input().split())))
		abra_ka_dabra1 = []
		for i in abra_ka_dabra:
			if i % k != 0:
				abra_ka_dabra1.append(k - i % k)
		if len(abra_ka_dabra1) == 0:
			print(0)
			continue
		abra_ka_dabra1.sort()
		ans = abra_ka_dabra1[0]
		curr = abra_ka_dabra1[0]
		for i in range(1, len(abra_ka_dabra1)):
			if abra_ka_dabra1[i] != abra_ka_dabra1[i - 1]:
				curr = abra_ka_dabra1[i]
			else:
				curr += k
			ans = max(ans, curr)
		print(ans + 1)
solution4()


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


from collections import defaultdict
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	for i in range(n):
		arr[i] = arr[i] % k
		arr[i] = k - arr[i]
	arr.sort(reverse=True)
	dic = defaultdict(bool)
	ct = defaultdict(int)
	ch = []
	for i in range(n):
		if arr[i] % k == 0:
			pass
		else:
			ele = arr[i] + k * ct[arr[i]]
			ct[arr[i]] += 1
			ch.append(ele)
	ch.sort()
	if len(ch) == 0:
		print(0)
	else:
		print(ch[-1] + 1)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	dic = {}
	for j in arr:
		if j % k != 0:
			dic[k - j % k] = dic.get(k - j % k, 0) + 1
	ans = 1
	ans2 = 1
	if len(dic) == 0:
		ans2 = 0
	temp = 0
	maxi = 0
	for kk in dic:
		if dic[kk] > temp or (dic[kk] == temp and kk > maxi):
			temp = dic[kk]
			maxi = kk
	ans2 = temp * k - (k - maxi - 1)
	if ans2 < 0:
		ans2 = 0
	print(ans2)


t = int(input())
for every in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if k == 1:
		print(0)
		continue
	b = {}
	s = set()
	l = 0
	for x in a:
		if x % k:
			s.add(k - x % k)
			if len(s) > l:
				b[k - x % k] = 0
				l += 1
			b[k - x % k] += 1
	ans = -1
	for i in s:
		ans = max(ans, i + k * (b[i] - 1))
	print(ans + 1)


from sys import *
input = stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	a = {}
	s = 0
	for i in l:
		x = i
		if i % k != 0:
			x = k - i % k
			a[x] = a.get(x, 0) + 1
	for (key, value) in a.items():
		s = max(s, key + (value - 1) * k)
	if s == 0:
		print(0)
	else:
		print(s + 1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
for _ in range(int(ri())):
	(n, k) = Ri()
	a = Ri()
	dic = {}
	maxx = -1
	for i in a:
		if i % k != 0:
			dic[i % k] = dic.get(i % k, 0) + 1
			tmaxx = (dic[i % k] - 1) * k + (k - i % k)
			maxx = max(tmaxx, maxx)
	print(maxx + 1)


import sys
from collections import defaultdict
input = lambda : sys.stdin.readline().strip()
t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	req = defaultdict(int)
	for i in range(n):
		temp = a[i] % k
		if temp == 0:
			continue
		req[k - temp] += 1
	val = 0
	ind = 0
	for (key, value) in req.items():
		if val <= value:
			if val < value:
				val = value
				ind = key
			elif key > ind:
				ind = key
	ans = val * k
	if ans != 0:
		ans -= k - ind - 1
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	arr = [(int(y) // k + 1) * k - int(y) if int(y) % k else 0 for y in input().split()]
	arr = sorted(arr)
	(max_move, k_now, i) = (0, 0, 0)
	while i < n:
		j = i
		adnd = 0
		if j < n - 1 and arr[j] != arr[j + 1]:
			if max_move < adnd + arr[j + 1]:
				max_move = adnd + arr[j + 1]
		else:
			while j < n - 1 and arr[j] == arr[j + 1] and (arr[j] != 0):
				adnd += k
				if max_move < adnd + arr[j + 1]:
					max_move = adnd + arr[j + 1]
				j += 1
		i = j + 1
	if len(arr) == 1:
		max_move = arr[0]
	print(max_move + 1 if max_move else max_move)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	c = {}
	d = {}
	for i in range(n):
		idx = a[i] // k * k + k - a[i]
		if idx == k and a[i] != 0:
			continue
		if c.get(idx):
			c[idx + k * d[idx]] = 1
			d[idx] += 1
		else:
			c[idx] = 1
			d[idx] = 1
	if c:
		print(max(c.keys()) + 1)
	else:
		print(0)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	c = {}
	for x in map(int, input().split()):
		y = x % k
		if y:
			y = k - y
			c[y] = c.get(y, 0) + 1
	ans = 0
	if c:
		for (x, y) in c.items():
			ans = max(ans, (y - 1) * k + x)
		ans += 1
	print(ans)


for t in range(int(input())):
	(n, k) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	arr = []
	for i in a:
		if i % k != 0:
			arr.append(k - i % k)
	if arr == []:
		print(0)
		continue
	dic = {}
	for i in arr:
		if i in dic.keys():
			dic[i] += 1
		else:
			dic[i] = 1
	array = []
	for i in dic.keys():
		array.append([dic[i], i])
	array.sort(key=lambda x: (x[0], x[1]))
	ans = (array[-1][0] - 1) * k
	ans += array[-1][1] + 1
	print(ans)


from collections import defaultdict
t = int(input())
for z in range(t):
	(n, k) = [int(q) for q in input().split()]
	a = [int(q) for q in input().split()]
	d = defaultdict(lambda : 0)
	for i in a:
		if i % k > 0:
			d[k - i % k] += 1
	ans = sorted(d.items(), key=lambda x: (x[1], x[0]), reverse=True)
	if d:
		r = ans[0][0]
		v = ans[0][1]
		print(r + (v - 1) * k + 1)
	else:
		print(0)


def solve():
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	m = dict()
	res = 0
	for i in range(n):
		if a[i] % k == 0:
			continue
		x = k - a[i] % k
		m[x] = m.get(x, 0) + 1
	for (key, v) in m.items():
		p = key + (v - 1) * k
		res = max(res, p)
	if res == 0:
		print(res)
	else:
		print(res + 1)
for _ in range(int(input())):
	solve()


t = int(input())
cnt = 0
while cnt < t:
	cnt += 1
	(n, k) = [int(i) for i in input().split()]
	d = {}
	flag = True
	minval = k
	maxval = 0
	for i in input().split():
		ind = int(i) % k
		d[ind] = d.get(ind, 0) + 1
		if ind != 0:
			flag = False
			if maxval < d[ind]:
				maxval = d[ind]
				minval = ind
			if maxval == d[ind] and ind < minval:
				minval = ind
	if flag == True:
		print(0)
	else:
		print(k * (maxval - 1) + k - minval + 1)


import sys
from collections import deque
t = int(input())

def inp():
	return sys.stdin.readline().strip()
for _ in range(t):
	(n, k) = map(int, inp().split())
	a = list(map(int, inp().split()))
	a = [(k - i % k) % k for i in a]
	a.sort()
	for i in range(n):
		if a[i] != 0:
			a = a[i:]
			break
		if i == n - 1:
			a = []
	if len(a) == 0:
		print(0)
		continue
	adict = dict()
	maxx = (0, -1)
	maxt = -1
	for i in a:
		g = adict.get(i, 0)
		adict[i] = g + 1
		maxx = max(maxx, (g + 1, i))
	if maxx[0] == 1:
		print(maxx[1] + 1)
	else:
		print(k * (maxx[0] - 1) + maxx[1] + 1)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	for i in range(n):
		if k - a[i] % k not in d and k - a[i] % k != k:
			d[k - a[i] % k] = 1
		elif k - a[i] % k != k:
			d[k - a[i] % k] += 1
	mx = -1
	ind = 0
	for i in d:
		if d[i] > mx:
			mx = d[i]
			ind = i
		elif d[i] == mx:
			ind = max(ind, i)
	if len(d) == 0:
		ans = 0
	else:
		ans = (mx - 1) * k + ind + 1
	print(ans)


from collections import *

def f(l, k):
	c = Counter(l)
	ans = 0
	for i in c.keys():
		if i == 0 or c[i] == 0:
			continue
		ans = max(ans, (c[i] - 1) * k + (k - i))
	return ans
t = int(input())
for _ in range(t):
	(_, k) = tuple(map(int, input().split()))

	def y(x):
		global k
		return int(x) % k
	l = list(map(y, input().split()))
	res = f(l, k)
	if res:
		print(res + 1)
	else:
		print(0)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	diff = [None] * n
	for i in range(n):
		mod = a[i] % k
		diff[i] = (k - mod) * (mod > 0) if a[i] >= k else k - a[i]
	diff.sort()
	for i in range(1, len(diff)):
		save = i
		if diff[i - 1] and diff[i - 1] == diff[i]:
			while i < len(diff) and diff[i] == diff[i - 1]:
				i += 1
			for j in range(save, i):
				diff[j] += (j - save + 1) * k
	ans = max(diff)
	print(ans + (ans != 0))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	dp = {}
	flag = 0
	for i in a:
		if i % k != 0 and k - i % k in dp:
			dp[k - i % k] = dp[k - i % k] + 1
			flag = 1
		elif i % k != 0:
			dp[k - i % k] = 1
			flag = 1
	x = 1
	c = 0
	o = list(dp.keys())
	for i in range(0, len(o)):
		if dp[o[i]] != 0:
			x = o[i] + (dp[o[i]] - 1) * k
			c = max(c, x)
	if flag != 0:
		print(c + 1)
	else:
		print(0)


import sys
input = sys.stdin.readline
from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	C = Counter(map(lambda i: k - i % k, A))
	r = 0
	for (key, v) in sorted(C.items()):
		if key == k:
			continue
		r = max(r, key + (v - 1) * k + 1)
	print(r)


from collections import defaultdict
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = defaultdict(int)
	ans = 0
	for a in l:
		d[k - a % k] += 1
		if a % k != 0:
			ans = max(ans, k - a % k + (d[k - a % k] - 1) * k)
	if ans == 0:
		print(0)
	else:
		print(ans + 1)


from collections import defaultdict

def solve():
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	h = defaultdict(int)
	mx = float('-inf')
	for a in arr:
		if a % k == 0:
			continue
		h[k - a % k] += 1
		mx = max(mx, h[k - a % k])
	ans = 0
	for i in h.items():
		if i[1] == mx:
			ans = max(ans, k * (mx - 1) + i[0] + 1)
	return ans

def main():
	t = int(input())
	while t:
		print(solve())
		t -= 1
main()


from typing import List

def zeroRemainderArray(n: int, k: int, array: List[int]) -> int:
	comp = [0 if i % k == 0 else k - i % k for i in array]
	dic = {}
	for num in comp:
		if num and num in dic:
			dic[num] += k
		else:
			dic[num] = num
	max_x = max(dic.values())
	return 0 if max_x == 0 else max_x + 1
test_cases = int(input())
for _ in range(test_cases):
	inputs = list(map(int, input().split(' ')))
	n = inputs[0]
	k = inputs[1]
	array = list(map(int, input().split(' ')))
	print(zeroRemainderArray(n, k, array))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	hashmap = {}
	number = 0
	for i in a:
		if i % k not in hashmap:
			hashmap[i % k] = 0
		hashmap[i % k] += 1
	for i in hashmap:
		if i != 0:
			number = max(number, k - i + (hashmap[i] - 1) * k)
	if number:
		print(number + 1)
	else:
		print(0)


from collections import defaultdict
t = int(input())
while t > 0:
	t -= 1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = []
	for i in a:
		if i % k != 0:
			z = i // k
			y = k * (z + 1) - i
			b.append(y)
	b.sort()
	if len(b) == 0:
		print(0)
	else:
		y = []
		y.append(b[0])
		for i in range(1, len(b)):
			m = len(y)
			if b[i] != b[i - 1]:
				y.append(b[i])
			else:
				y.append(y[m - 1] + k)
		print(max(y) + 1)


from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = [int(x) % k for x in input().split()]
	c = Counter(l)
	s = set(l)
	co = 0
	m = 0
	for i in s:
		if i != 0:
			co = (c[i] - 1) * k + k - i
			m = max(co, m)
	if m != 0:
		print(m + 1)
	else:
		print(0)


from collections import Counter
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		if a[i] % k == 0:
			a[i] = 0
		else:
			a[i] = k - a[i] % k
	c = Counter(a)
	ans = 0
	for (key, value) in c.items():
		if key == 0:
			continue
		x = key + (value - 1) * k
		if x > ans:
			ans = x
	if ans == 0:
		print(0)
	else:
		print(ans + 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	c = 0
	for i in range(n):
		x = k - a[i] % k
		if k == x:
			c += 1
		elif d.get(x) == None:
			d[x] = 1
		else:
			d[x] += 1
	if c == n:
		print(0)
		continue
	l = d.keys()
	ma = 0
	p = 0
	res = 0
	for i in l:
		if ma <= d[i]:
			ma = d[i]
			p = i
		res = max(res, (ma - 1) * k + 1 + p)
	print(res)


def solve(arr, n, k):
	aux = {}
	for i in arr:
		if i % k != 0:
			if k - i % k not in aux:
				aux[k - i % k] = 1
			else:
				aux[k - i % k] += 1
	ans = -1
	for i in aux:
		ans = max(ans, i + (aux[i] - 1) * k)
	print(ans + 1)
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	solve(arr, n, k)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	table = set()
	remtable = {}
	for i in a:
		if i % k != 0:
			rem = k - i % k
			if rem in remtable:
				last = remtable[rem][-1]
				remtable[rem].append(last + 1)
				index = rem + (last + 1) * k
			else:
				remtable[rem] = [0]
				index = rem
			table.add(index)
	if len(table) == 0:
		print(0)
	else:
		print(max(table) + 1)


for testcase in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	m = my = 0
	for ai in a:
		y = (k - ai % k) % k
		if y == 0:
			continue
		if y in d:
			d[y] += 1
		else:
			d[y] = 1
		if d[y] > m or (d[y] == m and y > my):
			m = d[y]
			my = y
	if not d:
		print(0)
	else:
		print((m - 1) * k + my + 1)


import sys
import math

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
t = int(input())
for _ in range(t):
	(n, k) = get_ints()
	arr = get_array()
	darr = []
	for i in range(n):
		if arr[i] % k != 0:
			darr.append(k - arr[i] % k)
	darr.sort()
	if len(darr) == 0:
		print(0)
		continue
	ans = darr[0]
	ptr = 0
	freq = [1]
	for i in range(1, len(darr)):
		if darr[i] == darr[i - 1]:
			freq[ptr] += 1
		else:
			freq.append(1)
			ptr += 1
	darr = list(set(darr))
	ans = 0
	for i in range(len(darr)):
		ans = max(ans, darr[i] + (freq[i] - 1) * k)
	print(ans + 1)


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	count = {}
	for i in range(n):
		A[i] %= k
	for i in range(n):
		if A[i] == 0:
			continue
		t = k - A[i]
		if t in count:
			count[t] += 1
		else:
			count[t] = 1
	ans = 0
	for c in count:
		ans = max(ans, c + (count[c] - 1) * k + 1)
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	for i in range(n):
		if arr[i] % k != 0:
			arr[i] = k - arr[i] % k
		else:
			arr[i] = 0
	arr.sort()
	index = 0
	maxi = 0
	cur = arr[0]
	count = 0
	for i in range(n):
		if arr[i] != 0:
			if arr[i] == cur:
				count += 1
			else:
				if count >= maxi:
					maxi = count
					index = arr[i - 1]
				cur = arr[i]
				count = 1
	if count >= maxi:
		maxi = count
		index = arr[-1]
	if maxi == 0:
		print(0)
	else:
		print(index + (maxi - 1) * k + 1)


t = int(input())
cases = []
for i in range(t):
	(n, kay) = input().split(' ')
	n = int(n)
	kay = int(kay)
	vals = input().split(' ')
	vals = [int(x) % kay for x in vals if int(x) % kay != 0]
	cases.append((n, kay, vals))
for c in cases:
	arr = c[2].copy()
	k = c[1]
	moves = 1
	x = 1
	if len(arr) == 0:
		print(0)
		continue
	m = {}
	for i in range(len(arr)):
		if arr[i] in m.keys():
			m[arr[i]] += 1
		else:
			m[arr[i]] = 1
	largest = -1
	max_key = 0
	for key in m:
		if m[key] == largest:
			if key < max_key:
				max_key = key
		elif m[key] > largest:
			largest = m[key]
			max_key = key
	final_value = (m[max_key] - 1) * k + (k + 1 - max_key)
	print(final_value)


from sys import stdin

def input():
	return next(stdin)

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		tab = input().split()
		for p in range(n):
			tab[p] = int(tab[p])
			tab[p] = k - tab[p] % k
		tab = sorted(tab)
		x = 0
		if tab[0] == k:
			print(0)
		elif n == 1:
			print(tab[0] + 1)
		else:
			x = tab[0]
			com = 0
			sup = 0
			num = 0
			for i in range(1, n):
				if tab[i] == k:
					break
				elif tab[i] == tab[i - 1]:
					com += 1
					if com > sup:
						sup = com
						num = tab[i]
					elif com == sup:
						num = tab[i]
				else:
					com = 0
			if sup == 0:
				if tab[i] == k:
					print(tab[i - 1] + 1)
				else:
					print(tab[i] + 1)
			else:
				print(num + 1 + sup * k)
main()


from collections import defaultdict
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	mod = [(a[i] % k, i) for i in range(n) if a[i] % k != 0]
	needed = [k - x[0] for x in mod]
	result = -1
	times = defaultdict(int)
	for val in needed:
		curVal = times[val] * k + val
		times[val] += 1
		result = max(result, curVal)
	print(result + 1)


import os
import sys
from io import BytesIO, IOBase
input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())

def main():
	try:
		for _ in range(inp()):
			(n, k) = invr()
			a = inlt()
			rems = []
			count = {}
			ans = 1
			for i in range(n):
				if a[i] % k != 0:
					number = k * (a[i] // k + 1) - a[i]
					if number not in count:
						count[number] = 1
						rems.append(number)
					else:
						rems.append(number + k * count[number])
						count[number] += 1
			if rems == []:
				print(0)
			else:
				print(max(rems) + 1)
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	numbers = list(map(int, input().split()))
	lookup = {}
	for i in numbers:
		if i % k != 0:
			if k - i % k not in lookup:
				lookup[k - i % k] = 1
			else:
				lookup[k - i % k] += 1
	ctr = 0
	for i in lookup:
		ctr = max(ctr, i + lookup[i] * k - k + 1)
	print(ctr)


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from copy import copy
from io import BytesIO, IOBase

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		ar = inpt()
		d = defaultdict(int)
		ans = 0
		for i in ar:
			if i % k == 0:
				continue
			v = k - i % k
			d[v] += 1
		if len(d) == 0:
			print(0)
			continue
		ans += 1
		mx = 0
		for i in d.keys():
			mx = max(mx, (d[i] - 1) * k + i)
		ans += mx
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		l = list(map(int, input().split()))
		for i in l:
			if i % k != 0:
				break
		else:
			print(0)
			continue
		s = {}
		for i in l:
			if i < k:
				rem = k - i
			elif i == k or i % k == 0:
				continue
			else:
				rem = (i // k + 1) * k - i
			if rem in s.keys():
				s[rem] += 1
				rem += k * (s[rem] - 1)
			s[rem] = 1
		print(max(s.keys()) + 1)
main()


from sys import stdin, stdout
import math
input = stdin.readline

def print(x='', y='', end='\n'):
	if y == '':
		stdout.write(str(x) + end)
	else:
		stdout.write(str(x) + ' ' + str(y) + end)

def solve():
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	cnt = {}
	for i in l:
		if i % k in cnt:
			cnt[i % k] += 1
		else:
			cnt[i % k] = 1
	ans = 0
	for i in cnt:
		if i == 0:
			continue
		ans = max(ans, cnt[i] * k - i)
	if ans:
		ans += 1
	print(ans)
tt = 1
tt = int(input())
for __ in range(tt):
	solve()


from collections import defaultdict
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = defaultdict(int)
	maxi = 0
	ele = k
	f = 0
	for i in l:
		if i % k != 0:
			f = 1
			d[i % k] += 1
			if d[i % k] >= maxi:
				if maxi == d[i % k]:
					ele = min(i % k, ele)
				else:
					ele = i % k
				maxi = d[i % k]
	if f == 0:
		print(0)
		continue
	ans = (maxi - 1) * k + k - ele
	print(ans + 1)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = {}
	index = 1
	if k == 1:
		print(0)
		continue
	d[0] = 0
	d[1] = 0
	for j in range(len(l)):
		a = l[j] % k
		if a in d:
			d[a] += 1
		else:
			d[a] = 1
	if d[0] == n:
		print(0)
		continue
	maxi = d[1]
	l1 = []
	for j in d:
		if j == 0:
			l1.append(0)
		else:
			l1.append((d[j] - 1) * k + (k - j))
	print(max(l1) + 1)


t = int(input())
for i in range(t):
	[n, k] = list(map(int, input().split()))
	A = list(map(int, input().split()))
	D = {}
	S = set()
	j = 0
	while j < len(A):
		A[j] = A[j] % k
		j += 1
	D = dict.fromkeys(A, 0)
	ans = 0
	for a in A:
		if a == 0:
			continue
		ans = max(ans, D[a] * k + (k - a) + 1)
		D[a] += 1
	print(ans)


import math

def solve():
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	dict = {}
	ans = 0
	need = 0
	for i in range(0, n):
		rem = (k - a[i] % k) % k
		if rem in dict.keys():
			dict[rem] += 1
		else:
			dict[rem] = 1
		if rem != 0:
			need = 1
	for i in dict:
		if i != 0:
			ans = max(ans, (dict[i] - 1) * k + i)
	print(0 if need == 0 else ans + 1)
t = 1
t = int(input())
for _ in range(0, t):
	solve()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	d = {}
	l = list(map(int, input().split()))
	for i in l:
		if i % k in d:
			d[i % k] += 1
		else:
			d[i % k] = 1
	maxx = 0
	for i in l:
		c = 0
		c = d[i % k]
		if i % k != 0:
			maxx = max(maxx, c * k - i % k)
	if maxx:
		print(maxx + 1)
	else:
		print(0)


import sys
t = int(sys.stdin.readline())
ans_arr = []
for i in range(t):
	[n, k] = [int(x) for x in sys.stdin.readline().split()]
	arr = [int(y) for y in sys.stdin.readline().split()]
	a = []
	for w in range(n):
		if arr[w] % k != 0:
			a.append(arr[w] % k)
	d = {}
	mx = -2
	flag = 1
	ele = -2
	for e in range(len(a)):
		if a[e] != 0:
			flag = 0
		if a[e] not in d:
			d[a[e]] = 1
		else:
			d[a[e]] += 1
		if d[a[e]] > mx:
			mx = d[a[e]]
			ele = a[e]
		elif d[a[e]] == mx and k - a[e] > k - ele:
			ele = a[e]
	if flag == 1:
		ans_arr.append(str(0))
	else:
		num = k - ele + (mx - 1) * k + 1
		ans_arr.append(str(num))
print('\n'.join(ans_arr))


from collections import Counter as Cnt
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(x) % k for x in input().split() if int(x) % k != 0]
	if not a:
		print(0)
	else:
		c = Cnt(a)
		print(max((1 - x + k * c[x] for x in c)))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	ar = [k - ar[i] % k for i in range(n)]
	ar = [i for i in ar if i != k]
	n = len(ar)
	if not ar:
		print(0)
		continue
	ar.sort()
	prv = ar[0]
	i = 1
	while i < n:
		cnt = 0
		j = i
		if prv == ar[j]:
			while j < n and prv == ar[j]:
				cnt += 1
				ar[j] += k * cnt
				j += 1
			j = i
		else:
			prv = ar[i]
			i += 1
	ar.sort()
	print(ar[-1] + 1)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = []
	for i in range(n):
		a[i] = a[i] % k
		if a[i] != 0:
			b.append(k - a[i])
	if len(b) == 0:
		print(0)
	else:
		b.sort()
		v = {}
		for i in b:
			if i in v.keys():
				v[i] = v[i] + k
			else:
				v[i] = i
		m = max(v.values())
		print(m + 1)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	new = []
	d = {}
	for i in range(n):
		if a[i] % k == 0:
			pass
		else:
			x = k - a[i] % k
			if d.get(x):
				y = d[x] * k + x
				d[x] += 1
				new.append(y)
			else:
				d[x] = 1
				new.append(x)
	print(max(new) + 1 if len(new) else 0)


t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	modDict = {}
	for j in a:
		modK = k - j % k
		if modK != k:
			if modK in modDict:
				modDict[modK] += 1
			else:
				modDict[modK] = 1
	if len(modDict.keys()) == 0:
		print(0)
	else:
		m = list(modDict.keys())[0]
		for (key, val) in modDict.items():
			if modDict[m] < val or (modDict[m] == val and m < key):
				m = key
		mval = modDict[m]
		re = (mval - 1) * k + m + 1
		print(re)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	b = list(map(int, input().split()))
	d = dict()
	r = 0
	for j in range(n):
		if b[j] % k != 0:
			if b[j] % k in d.keys():
				d[b[j] % k] += 1
			else:
				d[b[j] % k] = 1
			r = max(r, 1 + k - b[j] % k + (d[b[j] % k] - 1) * k)
	print(r)


import math as mt
import sys, string
input = sys.stdin.readline
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
from collections import defaultdict
t = I()
for _ in range(t):
	(n, k) = M()
	l = L()
	x = []
	d = defaultdict(int)
	m = 0
	key = 0
	for i in range(n):
		if l[i] % k != 0:
			d[k - l[i] % k] += 1
	for i in sorted(list(d.keys())):
		if m <= d[i]:
			m = d[i]
			key = i
	if m == 0:
		print(0)
	else:
		print((m - 1) * k + (key + 1))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lis = list(map(int, input().split()))
	rem = [(k - lis[i] % k) % k for i in range(n)]
	d = {}
	d[0] = -1
	for i in rem:
		if i == 0:
			continue
		if i in d:
			d[i] += k
		else:
			d[i] = i
	print(max(d.values()) + 1)


t = int(input())
while t:
	inp1 = list(map(int, input().strip().split()))[:2]
	(n, k) = (inp1[0], inp1[1])
	arr = list(map(int, input().strip().split()))[:n]
	dict1 = {}
	for i in arr:
		rem = i % k
		if rem:
			if k - rem in dict1:
				dict1[k - rem] += 1
			else:
				dict1[k - rem] = 1
	max1 = 0
	for i in dict1:
		max1 = max(max1, dict1[i])
	max2 = 0
	for i in dict1:
		if dict1[i] == max1:
			max2 = max(max2, i)
	ans = (max1 - 1) * k + max2 + 1
	if ans <= 0:
		print(0)
	else:
		print(ans)
	t -= 1


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, K, A):
	need = Counter()
	for x in A:
		need[-x % K] += 1
	if 0 in need and len(need) == 1:
		return 0
	best = 0
	for (num, count) in need.items():
		if num != 0:
			best = max(best, num + (count - 1) * K)
	return best + 1
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N, K) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	ans = solve(N, K, A)
	print(ans)


line = input()
t = int(line)
for j in range(t):
	line = input()
	(n, k) = [int(i) for i in line.split(' ')]
	line = input()
	nums = [int(i) for i in line.split(' ')]
	memo = {}
	for i in nums:
		memo[i % k] = memo.get(i % k, 0) + 1
	(r, last) = (0, 0)
	for (i, v) in memo.items():
		if i == 0:
			continue
		if v > r:
			r = memo[i]
			last = i
		elif v == r:
			last = min(i, last)
	if r == 0:
		print(0)
	else:
		print(r * k - last + 1)


t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	(n, k) = (l[0], l[1])
	l = list(map(int, input().split()))
	for i in range(n):
		if l[i] % k > 0:
			l[i] = k * (l[i] // k) + k - l[i]
		else:
			l[i] = 0
	if l == [0] * n:
		print(0)
	else:
		d = {}
		for i in l:
			if i not in d:
				d[i] = i
			elif i != 0:
				d[i] += k
		print(max(max(d.values()), max(d.keys())) + 1)


for t in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	cnt = {}
	for i in arr:
		i = i % k
		if i != 0:
			if cnt.get(i) == None:
				cnt[i] = 1
			else:
				cnt[i] += 1
	maxi = (0, 0)
	for i in cnt.items():
		if maxi[1] < i[1]:
			maxi = i
		if maxi[1] == i[1] and maxi[0] > i[0]:
			maxi = i
	if maxi[1] == 0:
		print(0)
	else:
		print(k * (maxi[1] - 1) + (k - maxi[0] + 1))


from sys import stdin, gettrace
from collections import Counter
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	(n, k) = map(int, inputi().split())
	aa = [-int(a) % k for a in inputi().split()]
	aac = Counter(aa)
	res = 0
	for (v, c) in aac.items():
		if v != 0:
			res = max(v + 1 + k * (c - 1), res)
	print(res)

def main():
	t = int(inputi())
	for _ in range(t):
		solve()
main()


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


t = int(input())
while t != 0:
	(n, k) = map(int, input().split())
	list1 = list(map(int, input().split()))
	list2 = list()
	dicto = {}
	for i in range(n):
		list2.append(k - list1[i] % k)
		if k - list1[i] % k in dicto.keys():
			if list1[i] % k == 0:
				continue
			dicto[k - list1[i] % k] += 1
		else:
			if list1[i] % k == 0:
				continue
			dicto[k - list1[i] % k] = 1
	maxi = 0
	if len(dicto) == 0:
		print(0)
	else:
		for i in dicto.keys():
			p = dicto[i]
			maxi = max(maxi, i + (dicto[i] - 1) * k)
		print(maxi + 1)
	t -= 1


for I in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	dic = {}
	for (i, num) in enumerate(a):
		a[i] = num % k
	dic = {}
	flag = False
	for (i, num) in enumerate(a):
		if num == 0:
			continue
		flag = True
		if num in dic:
			dic[num] += k
		else:
			dic[num] = k - num
	if not flag:
		print(0)
	else:
		print(max(dic.values()) + 1)


for test in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	max_x = 0
	count = {}
	for i in range(n):
		if a[i] % k != 0:
			count[a[i] % k] = 0
	for i in range(n):
		if a[i] % k != 0:
			count[a[i] % k] += 1
			max_x = max(max_x, (count[a[i] % k] - 1) * k + k - a[i] % k)
	if max_x > 0:
		max_x += 1
	print(max_x)


from collections import Counter
cases = int(input())
for t in range(cases):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	rem = []
	for i in a:
		d = i % k
		if d != 0:
			d = k - d
			rem.append(d)
	if rem:
		a = Counter(rem)
		(key, val) = (0, 0)
		for (i, v) in a.items():
			if v > val:
				val = v
				key = i
			elif v == val:
				key = max(key, i)
		print(key + (val - 1) * k + 1)
	else:
		print(0)


from sys import *
t = int(stdin.readline())
while t > 0:
	(n, k) = map(int, stdin.readline().split())
	arr = list(map(int, stdin.readline().split()))
	d = dict()
	d[0] = 0
	for i in arr:
		des = (k - i) % k
		if des:
			if des not in d:
				d[des] = des + 1
			else:
				d[des] += k
	print(max(d.values()))
	t -= 1


t = int(input())
for case in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	dif = [i % k for i in a if i % k != 0]
	if not dif:
		count = 0
	else:
		freq = {}
		most = 0
		for num in dif:
			if num not in freq.keys():
				freq[num] = 0
			freq[num] += 1
			most = max(most, freq[num])
		count = (most - 1) * k
		most_nums = sorted([num for num in freq.keys() if freq[num] == most])
		count += k - most_nums.pop(0) + 1
	print(count)


from collections import *
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	r = []
	for i in a:
		if i % k != 0:
			r.append(k - i % k)
	x = 0
	done = {}
	s = Counter(r)
	mx = 0
	for i in s:
		mx = max(mx, k * (s[i] - 1) + i)
	if mx:
		print(1 + mx)
	else:
		print(mx)


import sys
input = sys.stdin.readline
f = lambda : list(map(int, input().strip('\n').split()))
res = []
for _ in range(int(input())):
	(n, k) = f()
	inp = f()
	cnt = {}
	for i in inp:
		if not i % k:
			continue
		cnt[k - i % k] = cnt.get(k - i % k, 0) + 1
	if cnt.keys():
		num = max(cnt.keys(), key=lambda x: (cnt[x], x))
		ans = k * (cnt[num] - 1) + num + 1
	else:
		ans = 0
	res.append(ans)
print('\n'.join(map(str, res)))


from sys import stdin

def inp():
	return stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(n, k) = [int(x) for x in inp().split()]
	ar = [int(x) for x in inp().split()]
	dic = dict({})
	sett = set({})
	ans = 0
	bad = set({})
	for i in ar:
		if i not in sett:
			sett.add(i)
			dic[i] = 1
		else:
			dic[i] += 1
	for i in sett:
		if i % k != 0:
			freq = dic[i]
			needed = k - i % k
			while True:
				if needed not in bad:
					for i in range(freq - 1):
						bad.add(needed + (i + 1) * k)
					ans = max(ans, needed + (freq - 1) * k)
					bad.add(needed)
					break
				else:
					bad.add(needed)
					needed += k
	if ans != 0:
		print(ans + 1)
	else:
		print(ans)


from collections import defaultdict
inp = int(input())
for _ in range(inp):
	(n, k) = tuple(map(int, input().split()))
	ddict = defaultdict(int)
	seq = tuple(map(int, input().split()))
	for item in seq:
		ddict[item % k] += 1
	ddict[0] = 0
	value_max = float('-inf')
	for (key, value) in ddict.items():
		if value > value_max:
			value_max = value
			key_max = key
		if value == value_max and key < key_max:
			key_max = key
	if value_max == 0:
		print(0)
	else:
		print(value_max * k - key_max + 1)


from functools import reduce
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def inn():
	return int(input())
mo = 1000000007
for _ in range(inn()):
	(n, k) = value()
	l = arr()
	d = defaultdict(int)
	count = 0
	l.sort()
	for i in l:
		if i % k != 0:
			count += 1
			d[k - i % k] += 1
	if count == 0:
		print(0)
		continue
	ans = 0
	for i in d:
		val = d[i]
		ans = max(ans, i + k * (val - 1))
	print(ans + 1)


from collections import defaultdict

def func(li, k):
	cnt = defaultdict(int)
	for n in li:
		cnt[k - n % k] += 1
	if k in cnt:
		cnt.pop(k)
	if not cnt:
		print(0)
	else:
		maxi = max(((val, key) for (key, val) in cnt.items()))
		print(k * (maxi[0] - 1) + maxi[1] + 1)
cases = int(input())
for i in range(cases):
	(n, k) = map(int, input().split())
	li = map(int, input().split())
	func(li, k)


from collections import Counter
tc = int(input())
while tc > 0:
	(n, k) = map(int, input().split())
	c = Counter([k - a % k for a in map(int, input().split()) if a % k != 0])
	if c:
		(cnt, v) = max(map(lambda t: (t[1], t[0]), c.items()))
		print(v + k * (cnt - 1) + 1)
	else:
		print(0)
	tc -= 1


from collections import Counter
t = int(input())
for i in range(t):
	(n, k) = (int(x) for x in input().split())
	a = list(map(int, input().split()))
	am = [k - x % k for x in a if x % k > 0]
	if len(am) == 0:
		print(0)
	else:
		amc = Counter(am)
		amcm = [x[0] + 1 + k * (x[1] - 1) for x in amc.items()]
		print(max(amcm))


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True
for _ in range(ii()):
	(n, k) = mi()
	a = li()
	b = [k - a[i] % k for i in range(n)]
	d = collections.Counter(b)
	d.pop(k, None)
	ans = 0
	for i in d:
		ans = max(ans, i + (d[i] - 1) * k + 1)
	print(ans)


T = int(input())
while T > 0:
	T -= 1
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	D = {}
	for i in range(N):
		A[i] %= K
		A[i] = (K - A[i]) % K
		if A[i] > 0:
			if A[i] in D:
				D[A[i]] += 1
			else:
				D[A[i]] = 1
	c = 0
	j = 0
	for (x, y) in D.items():
		if y > c:
			c = y
			j = x
		elif y == c:
			if j < x:
				j = x
	ans = max(0, j + K * (c - 1) + 1)
	print(ans)


def solve():
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	pq = []
	for e in a:
		if e % k == 0:
			continue
		pq.append(k - e % k)
	pq.sort()
	q = []
	p = 0
	level = 1
	for e in pq:
		if e == p:
			level += 1
		else:
			level = 1
		q.append((level, e))
		p = e
	q.sort()
	return 0 if len(q) == 0 else (q[-1][0] - 1) * k + q[-1][1] + 1
T = int(input())
for case in range(T):
	print(solve())


import sys

class DZeroRemainderArray:

	def solve(self, tc=0):
		for _ in range(int(input())):
			(n, k) = [int(_) for _ in input().split()]
			a = [int(_) for _ in input().split()]
			for i in range(n):
				a[i] %= k
			mp = {x: 0 for x in a}
			for x in a:
				mp[x] += 1
			ans = 0
			for x in mp:
				if x == 0:
					continue
				ans = max(ans, (mp[x] - 1) * k + (k - x) + 1)
			print(ans)
solver = DZeroRemainderArray()
input = sys.stdin.readline
solver.solve()


t = int(input())
for casos in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = [k - int(i) % k for i in input().split() if int(i) % k != 0]
	a.sort()
	n = len(a)
	if n == 0:
		print(0)
	else:
		cnt = 1
		mxfreq = 1
		mxval = a[0]
		for i in range(1, len(a)):
			if a[i] == 0:
				continue
			if a[i] != a[i - 1]:
				if cnt >= mxfreq:
					mxval = a[i - 1]
					mxfreq = cnt
				cnt = 1
			else:
				cnt += 1
		if cnt >= mxfreq:
			mxval = a[n - 1]
			mxfreq = cnt
		print((mxfreq - 1) * k + mxval + 1)


def f(k, arr):
	x = 0
	arr = list(map(lambda r: r % k, arr))
	d = dict()
	c = 0
	for elem in arr:
		if elem != 0:
			if elem not in d.keys():
				d[elem] = 0
			d[elem] += 1
	if d == {}:
		return 0
	m = max(d.values())
	a = []
	for elem in d.keys():
		if d[elem] == m:
			a.append(elem)
	n = min(a)
	return k * m - n + 1
for i in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(f(k, arr))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	for i in range(n):
		arr[i] = arr[i] % k
	arr.sort()
	if arr[n - 1] == 0:
		print(0)
		continue
	ans = 0
	now = 1
	for i in range(0, n - 1):
		if arr[i] == arr[i + 1]:
			now += 1
			continue
		elif arr[i] != 0:
			qu = (now - 1) * k + k - arr[i] + 1
			ans = max(qu, ans)
			now = 1
		now = 1
	qu = (now - 1) * k + k - arr[n - 1] + 1
	ans = max(qu, ans)
	print(ans)


from math import log2
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	s = {}
	for i in range(len(l)):
		if l[i] / k == int(l[i] / k):
			pass
		elif -1 * (l[i] - (l[i] // k + 1) * k) in s:
			s[-1 * (l[i] - (l[i] // k + 1) * k)].append(l[i])
		else:
			s[-1 * (l[i] - (l[i] // k + 1) * k)] = []
			s[-1 * (l[i] - (l[i] // k + 1) * k)].append(l[i])
	(ll, kk) = (0, 0)
	if len(s) == 0:
		print(0)
	else:
		for (key, val) in sorted(s.items()):
			if len(val) > ll:
				ll = len(val)
				kk = key
			elif len(val) == ll and key > kk:
				kk = key
		print(k * (ll - 1) + kk + 1)


t = int(input())
for q in range(t):
	(n, k) = list(map(int, input().split(' ')))
	ent = list(map(int, input().split(' ')))
	resto = [0] * n
	cont = 0
	for i in range(n):
		c = k - ent[i] % k
		if c == k:
			resto[i] = 0
		else:
			resto[i] = k - ent[i] % k
		if resto[i] != 0:
			cont = 1
	if cont == 0:
		print(0)
	else:
		resto.sort()
		r = list(reversed(resto))
		m = r[0]
		cont = 1
		for j in range(0, n):
			if j != 0 and r[j] != 0:
				if r[j] == r[j - 1]:
					cont += 1
					m = max(m, r[j] + (cont - 1) * k)
				else:
					cont = 1
					m = max(m, r[j] + (cont - 1) * k)
		print(m + 1)


a = int(input())
d = {}
while a:
	d.clear()
	a = a - 1
	(n, k) = map(int, input().split())
	lis = list(map(int, input().split()))
	for i in range(len(lis)):
		it = lis[i]
		if it % k != 0:
			if k - it % k in d:
				d[k - it % k] += 1
			else:
				d[k - it % k] = 1
	ans = 0
	tt = 0
	for i in d:
		if d[i] > ans:
			ans = d[i]
			tt = i
		elif d[i] == ans:
			if i > tt:
				tt = i
	if ans > 0:
		ans = (ans - 1) * k + tt + 1
	print(ans)
	lis.clear()


from collections import defaultdict as dd
for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = dd(int)
	for i in a:
		d[i % k] += 1
	if 0 in d.keys():
		del d[0]
	m = 0
	s = []
	for i in d.keys():
		if d[i] > m:
			m = d[i]
			s = [i]
		elif d[i] == m:
			s.append(i)
	if len(s) == 0:
		print(0)
		continue
	mm = min(s)
	if m == 0:
		print(0)
		continue
	c = k - mm + (m - 1) * k + 1
	if mm == 0:
		c -= 1
	print(c)


from collections import defaultdict
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = defaultdict(int)
	for i in range(n):
		if a[i] % k == 0:
			pass
		else:
			d[a[i] % k] += 1
	ind = -1
	val = 0
	for i in d:
		if d[i] > val:
			val = d[i]
			ind = i
		elif d[i] == val:
			if i < ind:
				ind = i
	if ind == -1:
		print(0)
	else:
		print((val - 1) * k + k - ind + 1)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = int(z())
for _ in range(num):
	(n, k) = zz()
	lst = zzz()
	lst1 = []
	for i in lst:
		if i % k != 0:
			lst1.append(k - i % k)
	lst = dict(cc(lst1))
	mx = 0
	for i in lst:
		mx = max((lst[i] - 1) * k + i + 1, mx)
	print(mx)


from collections import Counter
from collections import OrderedDict

def SOCountR(mylist):
	return OrderedDict(sorted(Counter(mylist).items(), reverse=True))

def SOCount(mylist):
	return OrderedDict(sorted(Counter(mylist).items()))
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	x = 0
	l = []
	f = {}
	nex = {}
	ans = 0
	for i in range(n):
		p = a[i] % k
		if p == 0:
			continue
		else:
			p = k - p
			if f.get(p, 0) == 0:
				f[p] = 1
				ans = max(ans, p)
				nex[p] = k + p
			else:
				f[nex[p]] = 1
				ans = max(ans, nex[p])
				nex[p] = nex[p] + k
	if ans == 0:
		print(0)
	else:
		print(ans + 1)


tt = int(input())
for loop in range(tt):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	dic = {}
	for i in a:
		if i % k != 0:
			if k - i % k not in dic:
				dic[k - i % k] = 0
			dic[k - i % k] += 1
	mi = None
	for i in dic:
		if mi == None:
			mi = i
		elif dic[i] == dic[mi]:
			mi = max(i, mi)
		elif dic[i] > dic[mi]:
			mi = i
	if mi == None:
		print(0)
	else:
		print(k * (dic[mi] - 1) + mi + 1)


from sys import stdin, exit
input = stdin.readline

def i():
	return input()

def ii():
	return int(input())

def iis():
	return map(int, input().split())

def liis():
	return list(map(int, input().split()))

def print_array(a):
	print(' '.join(map(str, a)))
t = ii()
for _ in range(t):
	(n, k) = iis()
	a = liis()
	need = set()
	hashe = {}
	for i in a:
		jose = i % k
		if jose != 0:
			nome = k - jose
			if nome not in hashe:
				need.add(nome)
				hashe[nome] = nome
			else:
				need.add(hashe[nome] + k)
				hashe[nome] += k
	if len(need):
		print(max(need) + 1)
	else:
		print(0)


import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random
import string

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' ', end='\n'):
	print(sep.join(map(str, a)), end=end)

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
for _ in range(ii()):
	(n, k) = mi()
	d = li()
	p = dd()
	res = 0
	for i in d:
		if i % k == 0:
			continue
		x = k - i % k
		p[x] += 1
	for x in p:
		res = max(res, x + (k * (p[x] - 1) + 1))
	print(res)


from collections import defaultdict as dd
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = dd(int)
	if n == 1:
		if k % n != 0:
			print()
	for i in range(0, n):
		c = a[i] % k
		if c != 0:
			c = k - c
			if c not in d:
				d[c] = 1
			else:
				d[c] += 1
		else:
			d[c] += 1
	if len(d) == 1:
		if 0 in d:
			print(0)
			continue
	if 0 in d:
		d[0] = 0
	mx = max(d, key=d.get)
	mxv = -1
	for i in d.keys():
		if d[i] == d[mx] and i > mxv:
			mxv = i
	print((d[mx] - 1) * k + mxv + 1)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator
from collections import deque, defaultdict, OrderedDict
import collections

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		(n, k) = ria()
		a = ria()
		divadd = [0]
		d = {}
		for i in range(n):
			if a[i] % k != 0:
				z = k - a[i] % k
				if z not in d:
					divadd.append(z)
					d[z] = 1
				else:
					divadd.append(z + d[z] * k)
					d[z] += 1
		x = max(divadd)
		if x == 0:
			print(0)
		else:
			print(x + 1)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


from collections import Counter
t = int(input())
for _ in range(t):
	d = dict()
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	l = []
	for i in range(n):
		arr[i] = k - arr[i] % k
		if arr[i] % k != 0:
			l.append(arr[i])
	counter = dict(Counter(l))
	for (x, y) in counter.items():
		if y in d:
			d[y].append(x)
		else:
			d[y] = [x]
	for (x, y) in d.items():
		d[x] = sorted(d[x], reverse=True)
	values = sorted(d.keys(), reverse=True)
	if len(d) == 0:
		print(0)
	else:
		print(values[0] * k - (k - d[values[0]][0]) + 1)


from collections import Counter
import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	x = Counter()
	rC = Counter()
	m = []
	for i in arr:
		div = math.ceil(i / k) * k
		rem = div - i
		x[rem] = rem
	for i in sorted(arr, reverse=True):
		div = math.ceil(i / k) * k
		rem = div - i
		if rem == 0:
			continue
		m.append(x[rem])
		x[rem] += k
	if len(m) == 0:
		print(0)
	else:
		print(max(m) + 1)


from collections import defaultdict
t = int(input())
for kk in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	counter = defaultdict(int)
	for i in l:
		if i % k:
			in1 = k - i % k
			counter[in1] += 1
	if len(counter) != 0:
		d = k - len(counter) - 1
		counter[0] = 0
		ans = 1
		x = 1
		l1 = [(num, num1) for (num1, num) in counter.items()]
		l1.sort()
		ind1 = l1[-1][1]
		m = l1[-1][0]
		ans = k * (m - 1) + 1 + ind1
		print(ans)
	else:
		print(0)


def ops(arr, k):
	x = dict()
	for i in arr:
		cur = int(i) % k
		if cur:
			x[k - cur] = x.get(k - cur, 0) + 1
	ans = 0
	for i in x:
		cand = i + (x[i] - 1) * k
		ans = max(ans, cand)
	return ans + 1 if ans > 0 else ans
for _ in range(int(input())):
	t_k = input().split()
	k = int(t_k[1])
	arr = input().split()
	print(ops(arr, k))


import math
I = input
for _ in range(int(I())):
	(n, k) = map(int, I().split())
	a = list(map(int, I().split()))
	a1 = []
	for i in a:
		if i % k == 0:
			continue
		else:
			a1.append(math.ceil(i / k) * k - i)
	d = dict()
	for i in a1:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	read = dict.fromkeys(d.keys(), 1)
	for i in d:
		d[i] -= 1
	for i in d:
		t = i
		for _ in range(d[i]):
			read[t + k] = 1
			t += k
	print(max(read.keys()) + 1 if len(read) > 0 else 0)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	m = 0
	d = {}
	for i in a:
		if i % k not in d:
			d[i % k] = 1
		else:
			d[i % k] += 1
	for key in d:
		if key != 0:
			m = max(m, d[key] * k - key)
	if m != 0:
		m += 1
	print(m)


import sys
input = sys.stdin.readline
t = int(input())
while t:
	t = t - 1
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	ans = 0
	x = dict()
	for i in l:
		if i % k:
			if x.get(i % k):
				x[i % k] = x[i % k] + 1
			else:
				x[i % k] = 1
	for (key, values) in x.items():
		ans = max(ans, k - key + (values - 1) * k + 1)
	print(ans)


import sys
from collections import Counter
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	a = []
	for i in range(n):
		if l[i] % k == 0:
			a.append(0)
		else:
			a.append(k - l[i] % k)
	if sum(a) == 0:
		print(0)
		continue
	d = {}
	for i in range(len(a)):
		if a[i] == 0:
			continue
		if a[i] in d:
			d[a[i]] += 1
		else:
			d[a[i]] = 1
	keys = list(d.keys())
	m = 0
	for i in range(len(keys)):
		m = max(m, k * (d[keys[i]] - 1) + keys[i] + 1)
	print(m)


def mi():
	return map(int, input().split())
from collections import defaultdict
for _ in range(int(input())):
	(n, k) = mi()
	a = list(mi())
	for i in range(n):
		a[i] = a[i] % k
	a.sort(reverse=True)
	seen = defaultdict(int)
	ans = 0
	ma = -1
	lol = defaultdict(int)
	for i in range(n):
		if a[i]:
			t = k - a[i]
			if t > 0 and lol[t] == 0:
				lol[t] = t
			t = lol[t]
			if seen[t] == 1:
				t += k
				lol[t % k] = t
			ma = max(ma, t)
			seen[t] = 1
	print(ma + 1)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	mk = [(k - a[i] % k) % k for i in range(n)]
	mk.sort()
	mknodup = [mk[0]]
	nindx = 0
	for i in range(1, n):
		if mk[i] == 0:
			mknodup.append(0)
		elif mk[i] == mk[nindx]:
			mknodup.append(mk[i] + (i - nindx) * k)
		else:
			mknodup.append(mk[i])
			nindx = i
	mx = max(mknodup)
	if mx == 0:
		print(0)
	else:
		print(mx + 1)


import sys, math, cmath, time
start_time = time.time()

def solve():
	(n, k) = invr()
	a = inlt()
	a.sort()
	w = 0
	qw = []
	for i in range(len(a)):
		if a[i] % k != 0:
			qw.append(k - a[i] % k)
	if qw:
		w = 1
		qw.sort()
		for i in range(len(qw)):
			qw[i] = k - qw[i]
		qq = counter(qw)
		ww = []
		c = 0
		qwqw = len(qw)
		qq = list(qq.items())
		qq.reverse()
		qw = []
		for i in range(len(qq)):
			qw.append(list(qq[i]))
		while True:
			for i in range(len(qw) - 1, -1, -1):
				ww.append(qq[i][0])
				qw[i][1] = qw[i][1] - 1
				c = c + 1
			qq = []
			for i in range(len(qw)):
				if qw[i][1] > 0:
					qq.append(qw[i])
			qw = list(qq)
			if c >= qwqw:
				break
		qw = list(ww)
		for i in range(len(qw)):
			qq = qw[i] + w
			q = (qq + k) % k
			if q != 0:
				q = k - q
			w = w + q + 1
	print(w)

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

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

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

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def counter(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = (q[ord(a[i]) - 97], 1)
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


from collections import *
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	g = defaultdict(int)
	x = 0
	for i in map(int, input().split()):
		if i % k:
			g[k - i % k] += 1
	print(max((i + k * (g[i] - 1) + 1 for i in g)) if g else 0)


t = int(input())
for i in range(t):
	(n, k) = [int(i) for i in input().split()]
	a = [(k - int(i) % k) % k for i in input().split() if (k - int(i) % k) % k != 0]
	d = {}
	for i in a:
		if d.get(i) == None:
			d[i] = 1
		else:
			d[i] += 1
	if len(a) == 0:
		print(0)
	else:
		m = a[0]
		for key in d:
			if d[key] > d[m] or (d[key] == d[m] and key > m):
				m = key
		print((d[m] - 1) * k + m + 1)


def solve(arr, n, k, ans):
	mods = {}
	for i in range(n):
		arr[i] %= k
		arr[i] = (k - arr[i]) % k
		if arr[i] != 0:
			if arr[i] not in mods.keys():
				mods[arr[i]] = 0
			mods[arr[i]] += 1
	if not mods:
		ans.append(0)
		return
	dist_mods = []
	for mod in mods.keys():
		dist_mods.append((mods[mod], mod))
	dist_mods.sort()
	(count, mod) = dist_mods[-1]
	x = mod + (count - 1) * k
	x += 1
	ans.append(x)

def main():
	t = int(input())
	ans = []
	for i in range(t):
		(n, k) = map(int, input().split())
		arr = list(map(int, input().split()))
		solve(arr, n, k, ans)
	for i in ans:
		print(i)
main()


from math import *
from collections import deque
from copy import deepcopy
import sys

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def multi():
	return map(int, input().split())

def strmulti():
	return map(str, inp().split())

def lis():
	return list(map(int, inp().split()))

def lcm(a, b):
	return a * b // gcd(a, b)

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def stringlis():
	return list(map(str, inp().split()))

def out(var):
	sys.stdout.write(str(var))

def printlist(a):
	print(' '.join((str(a[i]) for i in range(len(a)))))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
t = int(input())
for j in range(t):
	(n, k) = multi()
	a = lis()
	needed = []
	for i in a:
		if i % k != 0:
			needed.append(k - i % k)
		else:
			needed.append(0)
	needed.sort()
	maxrepeat = 0
	num = 0
	hashy = {}
	for i in needed:
		if i not in hashy:
			hashy[i] = 1
			if hashy[i] >= maxrepeat and i != 0:
				maxrepeat = hashy[i]
				num = i
			continue
		if i in hashy:
			hashy[i] += 1
			if hashy[i] >= maxrepeat and i != 0:
				maxrepeat = hashy[i]
				num = i
	if num == 0:
		print(0)
	else:
		print(k * maxrepeat - (k - num) + 1)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = input()
	a = list(map(lambda x: int(x), a.split()))
	for i in range(n):
		a[i] = (k - a[i] % k) % k
	a = sorted(a)
	max_x = 0
	prev = -1
	curr_x = 0
	for i in range(n):
		if a[i] == 0:
			pass
		elif a[i] == prev:
			curr_x = curr_x + k
			max_x = max(max_x, curr_x)
		else:
			curr_x = a[i]
			max_x = max(max_x, curr_x)
		prev = a[i]
	if max_x > 0:
		max_x += 1
	print(max_x)


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

def main():
	task_D()
main()


input_length = int(input())
while input_length != 0:
	nk_string = str(input())
	(n, k) = tuple(nk_string.split())
	(n, k) = (int(n), int(k))
	array_now_string = str(input())
	input_length -= 1
	array_now = array_now_string.split()
	array_now = [int(x) for x in array_now]
	remainder_array = [(x // k + 1) * k - x if x % k != 0 else 0 for x in array_now]
	remainder_array = sorted(remainder_array)
	(temp, iter1, count) = (0, 0, 0)
	for i in range(0, len(remainder_array)):
		if remainder_array[i] == 0:
			continue
		if remainder_array[i] == temp:
			iter1 += 1
			remainder_array[i] += iter1 * k
		elif remainder_array[i] != temp:
			temp = remainder_array[i]
			iter1 = 0
	last_value = 0
	x = 0
	remainder_array = sorted(remainder_array)
	for new_value in remainder_array:
		if new_value != 0 and x == 0:
			count += 1
			x += 1
		count += new_value - last_value
		last_value = new_value
	print(count)


import sys
import operator
infile = sys.stdin
next(infile)
for line in infile:
	l = list(map(int, line.split()))
	n = l[0]
	k = l[1]
	x = 0
	a = list(map(int, next(infile).split()))
	r = [ai % k for ai in a]
	rc = {}
	for ri in r:
		if ri in rc.keys():
			rc[ri] += 1
		else:
			rc[ri] = 1
	tempmax = max(rc.values())
	if tempmax == n:
		if 0 in rc.keys():
			step = 0
		else:
			step = n * k - r[0] + 1
	else:
		rc[0] = 0
		rcs = dict(sorted(rc.items()))
		maxi = max(rcs.values())
		indi = max(rcs.items(), key=operator.itemgetter(1))[0]
		step = int(maxi) * k - int(indi) + 1
	print(step)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = (k - a[i] % k) % k
	a.sort()
	i = a.count(0)
	mv = a[n - 1]
	while i < n:
		(cv, cnt) = (a[i], 1)
		while i + 1 < n and a[i + 1] == a[i]:
			mv = max(mv, cv + cnt * k)
			i += 1
			cnt += 1
		i += 1
	print(mv + 1 if mv > 0 else 0)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	li = list(map(int, input().split()))
	li2 = [0]
	for i in li:
		if i % k == 0:
			li2.append(0)
		else:
			li2.append(k - i % k)
	li2 = sorted(li2)
	z = li2[::-1].index(0)
	li2 = li2[n - z:]
	mx = -1
	for i in range(1, len(li2)):
		if li2[i] % k != li2[i - 1] % k:
			mx = max(mx, li2[i])
		else:
			li2[i] = li2[i - 1] + k
			mx = max(mx, li2[i])
	print(mx + 1)


a = int(input())
for i in range(a):
	(leng, k) = map(int, input().split())
	a = list(map(int, input().split()))
	count = {}
	for i in a:
		if i % k == 0:
			continue
		if count.get(k - i % k, 0):
			count[k - i % k] += 1
		else:
			count.update({k - i % k: 1})
	temp = [0, 0]
	for (i, j) in count.items():
		if j > temp[1] or (j == temp[1] and i > temp[0]):
			temp = [i, j]
	res = temp[0] + (temp[1] - 1) * k + 1
	if res <= 0:
		print(0)
	else:
		print(temp[0] + (temp[1] - 1) * k + 1)


from collections import defaultdict
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = defaultdict(int)
	s = set()
	for i in a:
		x = k - i % k
		if x == k:
			continue
		else:
			d[x] += 1
			s.add(x)
	if len(s) == 0:
		print(0)
	else:
		c = 0
		for i in d:
			x = i + 1 + (d[i] - 1) * k
			c = max(c, x)
		print(c)


t = int(input())
while t > 0:
	t = t - 1
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	mp = {}
	ans = 0
	for i in range(len(arr)):
		val = arr[i] % k
		if val != 0:
			hh = k - val
			if hh in mp:
				mp[hh] += 1
			else:
				mp[hh] = 1
	for (val, cnt) in mp.items():
		z = val + (cnt - 1) * k
		ans = max(ans, z)
	if ans != 0:
		ans += 1
	print(ans)


t = int(input())
for test in range(t):
	(n, k) = [int(i) for i in input().split()]
	s = [int(i) for i in input().split()]
	d = {}
	for i in s:
		if i % k != 0:
			if i % k in d:
				d[i % k] += 1
			else:
				d[i % k] = 0
	x = 0
	y = k
	for (u, a) in d.items():
		if a > x:
			x = a
			y = u
		elif a == x:
			y = min(y, u)
	print(k * x + (k - y + 1) * (y != k))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = []
	ff = 0
	for i in range(n):
		if a[i] % k == 0:
			ff += 1
		else:
			b.append(k - a[i] % k)
	pp = {}
	for i in range(len(b)):
		if b[i] in pp:
			pp[b[i]] += k
		else:
			pp[b[i]] = b[i]
	if len(pp.values()) > 0:
		aa = max(pp.values())
		print(aa + 1)
	else:
		print(0)


from collections import Counter
for i in range(int(input())):
	(n, k) = map(int, input().split())
	num = list(map(int, input().split()))
	ans = 0
	p = Counter()
	for j in range(n):
		if num[j] % k == 0:
			continue
		p[k - num[j] % k] += 1
		ans = max(ans, (p[k - num[j] % k] - 1) * k + (k - num[j] % k))
	print(min(ans, 1) + ans)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	ar = list(map(int, input().split()))
	ans = 0
	fifi = dict()
	flag = False
	for elem in ar:
		j = 0
		if elem % k not in fifi:
			fifi[elem % k] = 0
		num = (elem + k - 1) // k * k + k * fifi[elem % k] - elem
		ans = max(num, ans)
		if elem % k != 0:
			fifi[elem % k] += 1
			flag = True
	if flag:
		print(ans + 1)
	else:
		print(ans)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	needs = []
	found = {}
	d = 0
	for v in a:
		s = k - v % k
		b = s if v % k != 0 else 0
		if b == 0:
			d += 1
		if b not in found and b != 0:
			found[b] = 1
		elif b != 0:
			found[b] += 1
			b += k * (found[b] - 1)
		needs.append(b)
	if d != n:
		print(max(needs) + 1)
	else:
		print(0)


import os
is_dev = 'vscode' in os.environ
if is_dev:
	inF = open('in.txt', 'r')
	outF = open('out.txt', 'w')

def ins(r):
	return list(map(int, r.split(' ')))

def inputT():
	if is_dev:
		return inF.readline()[:-1]
	else:
		return input()

def printT(data=''):
	if is_dev:
		return outF.write(str(data) + '\n')
	else:
		return print(data)
from collections import Counter
for _ in range(int(inputT())):
	(n, k) = ins(inputT())
	a = ins(inputT())
	a = [k - x % k for x in a if x % k]
	a = list(Counter(a).items())
	if len(a) == 0:
		printT(0)
		continue
	maxa = max(a, key=lambda x: (x[1], x[0]))
	printT((maxa[1] - 1) * k + maxa[0] + 1)
if is_dev:
	outF.close()
	print(open('out.txt', 'r').read() == open('outactual.txt', 'r').read())


from collections import Counter

def solve(n, k, l):
	x = 0
	ans = 0
	rem = [0 for i in range(n)]
	for i in range(n):
		rem[i] = (k - l[i] % k) % k
	rem = sorted(rem)
	c = Counter(rem)
	count = 0
	done = 0
	m = []
	for i in sorted(c.keys()):
		if i == 0 or i == k:
			continue
		done = 1
		g = c[i] - 1
		m.append(g * k + i)
		temp = i
	if len(m) == 0:
		return 0
	else:
		ans = max(m)
	if done == 1:
		ans += 1
	return ans
t = int(input())
for we in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	print(solve(n, k, l))


from collections import *
R = lambda : map(int, input().split())
(j,) = R()
for _ in [0] * j:
	(n, k) = R()
	c = Counter((x % k for x in R()))
	print(max((x and 1 - x + k * c[x] for x in c)))


T = int(input())
for _ in range(T):
	(n, k) = map(int, input().strip().split())
	a_list = map(int, input().strip().split())
	divisors = {}
	_mode = 0
	for a in a_list:
		div = a % k
		if div == 0:
			continue
		elif div in divisors:
			divisors[div] += 1
		else:
			divisors[div] = 1
		_mode = max(divisors[div], _mode)
	min_d = k
	for (d, count) in divisors.items():
		if count == _mode:
			min_d = min(min_d, d)
	if _mode == 0:
		print(0)
	else:
		print(k * (_mode - 1) + (k - min_d) + 1)


import sys
from fractions import gcd
from math import ceil, sqrt, sin, pi, tan
from collections import defaultdict
read = sys.stdin.buffer.readline
import heapq
mi = lambda : map(int, read().split())
li = lambda : list(mi())
cin = lambda : int(read())
as0 = ord('0')
as1 = ord('1')
for _ in range(cin()):
	(n, k) = mi()
	d = {}
	a = li()
	ans = 0
	for i in range(n):
		dif = k - a[i] % k
		if dif == k:
			continue
		elif dif in d:
			d[dif] += 1
		else:
			d[dif] = 1
	for el in list(d.keys()):
		ans = max(ans, el + k * (d[el] - 1) + 1)
	print(ans)


n = int(input())
for _ in range(n):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	z = []
	l = {}
	for i in a:
		if i % k:
			h = i // k
			h = (h + 1) * k - i
			if h not in l:
				l[h] = 0
			b = l[h] * k + h
			l[h] += 1
			z.append(b)
	if z == []:
		print(0)
	else:
		print(max(z) + 1)


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split(' '))
	l = list(map(int, input().split(' ')))
	dic = {}
	for x in range(n):
		dic[x] = k - l[x] % k
	s = {}
	ans = 0
	for (x, y) in sorted(dic.items(), key=lambda x: x[1]):
		if y != k:
			if y not in s.keys():
				s[y] = 1
			else:
				s[y] = s[y] + 1
			ans = max(ans, k * (math.floor(l[x] / k) + s[y]) - l[x])
	if ans == 0:
		print(0)
	else:
		print(ans + 1)


import sys
from collections import Counter
input = lambda : sys.stdin.readline().strip('\r\n')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = -a[i] % k
	c = Counter(a)
	ans = 0
	for (key, val) in c.items():
		if key:
			ans = max(ans, key + (val - 1) * k + 1)
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l1 = []
	for i in range(n):
		if l[i] % k != 0:
			l1.append(k - l[i] % k)
	if len(l1) == 0:
		print(0)
	else:
		l1.sort()
		t = 1
		temp = 0
		mv = l1[-1]
		for i in range(1, len(l1)):
			if l1[i] == l1[i - 1]:
				t += 1
			else:
				if t >= temp:
					temp = t
					mv = l1[i - 1]
				t = 1
		if t >= temp:
			temp = t
			mv = l1[-1]
		print((temp - 1) * k + mv + 1)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = [(k - x) % k for x in map(int, input().split())]
	a.sort()
	prev = -1
	max_v = 0
	max_c = 0
	cur_c = 0
	for x in a:
		if x == prev:
			cur_c += 1
		else:
			cur_c = 0
		if cur_c >= max_c and x % k != 0:
			max_c = cur_c
			max_v = x + 1
		prev = x
	print(k * max_c + max_v)


import math
from collections import *
import math

def solve():
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	d = defaultdict(int)
	maxi = 0
	for i in range(n):
		if a[i] % k == 0:
			continue
		d[k - a[i] % k] += 1
	ans = 0
	for i in d:
		ans = max(k * (d[i] - 1) + i + 1, ans)
	print(ans)
t = int(input())
for _ in range(t):
	solve()


import math
t = int(input())
for i in range(t):
	(n, k) = [int(j) for j in input().split()]
	arr = [int(j) for j in input().split()]
	for j in range(n):
		arr[j] = (k - arr[j] % k) % k
	arr.sort()
	sol = [-1 for j in range(n)]
	x = 0
	maxx = 0
	if sum(arr) > 0:
		for j in range(0, n):
			if arr[j] != 0:
				if j == 0:
					maxx = max(maxx, arr[j] + x + 1)
					continue
				if arr[j] > arr[j - 1]:
					x = 0
				else:
					x += k
			maxx = max(maxx, arr[j] + x + 1)
	print(maxx)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = dict()
	curmax = 0
	for i in l:
		temp = k - i % k
		if temp == k:
			continue
		if temp in d:
			t = temp
			temp += d[temp] * k
			d[t] += 1
		curmax = max(temp, curmax)
		d[temp] = 1
	if curmax == 0:
		print(0)
	else:
		print(curmax + 1)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	di = dict()
	mx = 0
	for j in input().split():
		x = (k - int(j) % k) % k
		if x:
			cnt = di.get(x, 0)
			mx = max(mx, cnt + x)
			di[x] = cnt + k
	if mx:
		print(mx + 1)
	else:
		print(0)


t = int(input())
while t:
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	max = 0
	curr = 0
	d1 = {}
	for i in a:
		temp = i % k
		if temp != 0:
			if k - temp in d1.keys():
				d1[k - temp] += 1
				if d1[k - temp] > max:
					curr = k - temp
					max = d1[k - temp]
				elif d1[k - temp] == max:
					if k - temp > curr:
						curr = k - temp
						max = d1[k - temp]
			else:
				d1[k - temp] = 1
				if d1[k - temp] > max:
					curr = k - temp
					max = d1[k - temp]
				elif d1[k - temp] == max:
					if k - temp > curr:
						curr = k - temp
						max = d1[k - temp]
	if max == 0:
		print(0)
	else:
		print((max - 1) * k + curr + 1)
	t = t - 1


import sys
input = sys.stdin.buffer.readline
from math import *
import os
import copy
from bisect import *
t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	brr = []
	for x in arr:
		brr.append(k - x % k)
	brr.sort()
	move = 0
	na = []
	var = 0
	i = 0
	while i < n:
		var = bisect_right(brr, brr[i]) - bisect_left(brr, brr[i])
		if brr[i] % k != 0:
			na.append((var - 1) * k + brr[i])
			i += var
		else:
			i += var
	if len(na) == 0:
		print('0')
	else:
		print(max(na) + 1)


t = int(input())
while t > 0:
	t -= 1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	left = []
	for i in a:
		if i % k != 0:
			left.append(i % k)
	if len(left) == 0:
		print(0)
		continue
	left.sort()
	count = {}
	for i in left:
		count[i] = count.get(i, 0) + 1
	max = 0
	x = -1
	for i in left:
		if max < count[i]:
			x = i
			max = count[i]
	ans = k * (max - 1) + k - x + 1
	print(ans)


from collections import Counter
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	(*a,) = map(int, input().split())
	a = [(k - ai % k) % k for ai in a]
	ca = Counter(a)
	ans = [(ca[i] - 1) * k + i for i in ca if i]
	if ans:
		print(max(ans) + 1)
	else:
		print(0)


t = int(input())
while t > 0:
	(n, k) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	for i in range(n):
		arr[i] = arr[i] % k
	dic = {}
	for i in range(n):
		if arr[i] in dic:
			dic[arr[i]] += 1
		else:
			dic[arr[i]] = 1
	maxi = 0
	count = 0
	for j in dic.keys():
		if dic[j] > count and j != 0:
			maxi = j
			count = dic[j]
		elif dic[j] == count and j < maxi and (j != 0):
			maxi = j
			count = dic[j]
	if count == 0:
		print(0)
	else:
		print(k * (count - 1) + k - maxi + 1)
	t -= 1


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


import math
from collections import Counter, deque
L = lambda : list(map(int, input().split()))
M = lambda : map(int, input().split())
I = lambda : int(input())
IN = lambda : input()
mod = 10 ** 9 + 7

def s(a):
	print(' '.join(list(map(str, a))))

def solve():
	(n, k) = M()
	a = L()
	d = {}
	ans = 0
	f = 0
	for i in range(n):
		x = k - a[i] % k
		if x % k == 0:
			continue
		f = 1
		if x in d:
			d[x] += 1
		else:
			d[x] = 1
	for i in d:
		ans = max(k * (d[i] - 1) + i, ans)
	if f:
		print(ans + 1)
	else:
		print(0)
for i in range(I()):
	solve()


import sys
from collections import defaultdict
readline = sys.stdin.readline
t = int(readline())
for _ in range(t):
	(n, k) = map(int, readline().split())
	A = map(int, readline().split())
	cnt = defaultdict(int)
	for a in A:
		cnt[a % k] += 1
	cnt[0] = 0
	ans = 0
	for (r, c) in cnt.items():
		if ans < (c - 1) * k + k - r:
			ans = (c - 1) * k + k - r
	if ans != 0:
		ans += 1
	print(ans)


from collections import Counter
t = int(input())
for i in range(t):
	(n, k) = [int(v) for v in input().split()]
	w = [k - int(v) % k for v in input().split()]
	eta = []
	for j in w:
		if j != k:
			eta.append(j)
	q = Counter(eta)
	eta = [[q[a], a] for a in q.keys()]
	eta.sort()
	if not eta:
		print(0)
	else:
		res = (eta[-1][0] - 1) * k + eta[-1][1] + 1
		print(res)


from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	c = Counter((v % k for v in map(int, input().split()) if v % k))
	if c:
		x = max(c.values())
		y = min((v for v in c if c[v] == x))
		print((x - 1) * k + k - y + 1)
	else:
		print(0)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	d = {}
	ans = 0
	for i in map(int, input().split()):
		if i % k:
			d[i % k] = d.get(i % k, 0) + 1
			ans = max(ans, k * d[i % k] - i % k + 1)
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	ls = list(map(int, input().split()))
	mod_dict = {}
	for item in ls:
		mod = item % k
		if mod in mod_dict:
			mod_dict[item % k] += 1
		else:
			mod_dict[item % k] = 1
	if 0 in mod_dict and mod_dict[0] == n:
		print(0)
	else:
		maxi = 0
		maxi_mod = None
		for mod in mod_dict:
			if mod != 0:
				if maxi < mod_dict[mod]:
					maxi = mod_dict[mod]
					maxi_mod = mod
				if maxi == mod_dict[mod] and maxi_mod > mod:
					maxi_mod = mod
		print(k * (maxi - 1) + k - maxi_mod + 1)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		if a[i] % k == 0:
			a[i] = k
		else:
			a[i] = a[i] % k
	a.sort()
	c = k - a[0]
	d = [c]
	for i in range(1, n):
		if a[i] == a[i - 1] and a[i] != k:
			d.append(d[-1] + k)
		else:
			d.append(k - a[i])
	if sum(d) == 0:
		print(0)
	else:
		print(max(d) + 1)


from collections import *
for _ in range(int(input())):
	(N, K) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	dic = defaultdict()
	for i in range(N):
		t = K - A[i] % K
		if t != K:
			if t not in dic:
				dic[K - A[i] % K] = 1
			else:
				dic[t] += 1
	if len(dic) == 0:
		print(0)
	else:
		dic = sorted(dic.items(), key=lambda c: c[1])
		maxa = dic[-1][0]
		t = dic[-1][1]
		for i in range(len(dic) - 1, -1, -1):
			if dic[i][1] == t:
				maxa = max(maxa, dic[i][0])
			else:
				break
		print(K * (t - 1) + maxa + 1)


from collections import *
for u in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = defaultdict(int)
	for i in l:
		d[i % k] += 1
	ll = list(d.keys())
	dd = list(d.values())
	g = len(ll)
	x = 0
	for i in range(g):
		if ll[i] != 0:
			x = max(x, (dd[i] - 1) * k + (k - ll[i]) + 1)
	print(x)


import sys
from collections import Counter
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
tc = int(input())
last = []
while tc:
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	brr = []
	for ele in arr:
		temp = ele % k
		if temp == 0:
			brr.append(temp)
		else:
			brr.append(k - temp)
	fa = Counter(brr)
	mas = -1
	for ele in fa:
		va = fa[ele]
		if ele == 0:
			continue
		mas = max(mas, k * (va - 1) + ele)
	last.append(str(mas + 1))
	tc -= 1
print('\n'.join(last))


t = int(input())
while t:
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = []
	for i in range(0, n):
		if a[i] % k != 0:
			b.append(a[i] % k)
	b.sort()
	ans = 0
	i = 0
	while i < len(b):
		cnt = 0
		while i < len(b) - 1 and b[i + 1] == b[i]:
			cnt += 1
			i += 1
		ans = max(ans, (cnt + 1) * k - b[i])
		i += 1
	if ans != 0:
		print(ans + 1)
	else:
		print('0')
	t -= 1


t = int(input())
for _ in range(t):
	(n, k) = (int(var) for var in input().split())
	arr = [int(var) for var in input().split()]
	remainder = {}
	maxMoves = -1
	for num in arr:
		rem = num % k
		if rem != 0:
			remainder[rem] = remainder.get(rem, 0) + 1
	for rem in remainder:
		cnt = remainder[rem]
		reqd = k - rem
		maxMoves = max(maxMoves, reqd + (cnt - 1) * k)
	print(maxMoves + 1)


import sys, os
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
input = lambda : sys.stdin.readline().strip()
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
for _ in range(I()):
	(n, k) = li()
	l = li()
	d = {(k - l[i]) % k: 0 for i in range(n)}
	for i in l:
		t = (k - i) % k
		if t > 0:
			d[t] += 1
	m = -1
	mi = -1
	for i in d:
		m = max(k * (d[i] - 1) + i, m)
	print(m + 1)


from collections import defaultdict
a = int(input())
for i in range(a):
	(n, k) = map(int, input().split())
	temp = list(map(int, input().split()))
	z = []
	for i in range(len(temp)):
		if temp[i] % k != 0:
			z.append(temp[i])
	ans = []
	if len(z) == 0:
		print(0)
		continue
	for i in range(len(z)):
		z[i] = k - z[i] % k
	z.sort()
	count = 1
	for i in range(1, len(z)):
		if z[i] == z[i - 1]:
			count += 1
		else:
			ans.append(z[i - 1] + (count - 1) * k)
			count = 1
	ans.append(z[-1] + (count - 1) * k)
	if len(ans) == 0:
		print(0)
	else:
		print(max(ans) + 1)


def divisible(n, a, k):
	dct = {}
	for i in range(n):
		if (k - a[i] % k) % k == 0:
			continue
		dct[(k - a[i] % k) % k] = dct.get((k - a[i] % k) % k, 0) + 1
	y = list(dct.items())
	if y:
		x = max(dct.items(), key=lambda x: (x[-1], x[0]))
		if len(dct.items()) == n and n == k:
			return k
		return x[0] + k * (x[1] - 1) + 1
	else:
		return 0
q = int(input())
for _ in range(q):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	print(divisible(n, a, k))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	aa = [int(a) for a in input().split()]
	b = []
	for i in range(len(aa)):
		c = k - aa[i] % k
		if c != k:
			b.append(c)
	freq = {}
	for item in b:
		if item in freq:
			freq[item] += 1
		else:
			freq[item] = 1
	ans = 0
	for (key, value) in freq.items():
		m = k * (value - 1) + key
		ans = max(ans, m)
	if ans == 0:
		print(0)
	else:
		print(ans + 1)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	b = list(map(int, input().split()))
	d = dict()
	p = 0
	for j in range(n):
		if b[j] % k != 0:
			if b[j] % k in d.keys():
				d[b[j] % k] += 1
			else:
				d[b[j] % k] = 1
			p = max(p, 1 + k - b[j] % k + (d[b[j] % k] - 1) * k)
	print(p)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	rem = []
	for i in range(n):
		if a[i] % k != 0:
			rem.append(k - a[i] % k)
	arr = {}
	if not rem:
		print(0)
		continue
	for el in rem:
		try:
			_ = arr[el]
			arr[el] += k
		except:
			arr[el] = el
	m = max(arr.values())
	print(0 if m == 0 else m + 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = dict()
	for i in range(n):
		if a[i] % k == 0:
			continue
		else:
			s = a[i] // k + 1
			p = s * k - a[i]
			d[p] = d.get(p, 0) + 1
	m = 0
	for (k1, v) in d.items():
		q = k1 + (v - 1) * k
		m = max(m, q)
	if m == 0:
		print(0)
	else:
		print(m + 1)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for j in range(n):
		a[j] = k - a[j] % k
		if a[j] == k:
			a[j] = 0
	a.sort()
	res = a[0]
	cnt = 1
	for j in range(1, n):
		if a[j] < 1:
			cnt = 0
			continue
		if a[j] == a[j - 1]:
			cnt += 1
		else:
			cnt = 1
		res = max(res, (cnt - 1) * k + a[j])
	if res:
		res += 1
	print(res)


def ints():
	return list(map(int, input().split()))
from collections import Counter, OrderedDict
for _ in range(int(input())):
	(n, k) = ints()
	a = ints()
	d = Counter()
	for i in range(n):
		p = a[i] % k
		if p == 0:
			continue
		d[p - k] += 1
	if d == {}:
		print(0)
		continue
	ans = 0
	r = 0
	i = 0
	dd = OrderedDict(sorted(d.items(), reverse=True))
	f = 0
	for x in dd:
		p = d[x]
		p -= r
		if p > 0:
			if f == 0:
				ans += 1
				f = 1
			ans += abs(x) - i
			i = abs(x)
			p -= 1
		if p > 0:
			ans += k * p
			r += p
	print(ans)


t = input()
t = int(t)
while t:
	t = t - 1
	st = input()
	(n, k) = map(int, st.split())
	pt = input()
	lst = [int(m) for m in pt.split()]
	dic = {}
	MAX = -1
	for i in range(0, n):
		re = lst[i] % k
		if re == 0:
			continue
		if re not in dic:
			dic[re] = 0
		dic[re] = dic[re] + 1
		MAX = max(MAX, k - re + (dic[re] - 1) * k)
	print(MAX + 1)


import collections
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = [a[i] % k for i in range(n)]
	ctr = collections.Counter(b)
	c = [0]
	for (key, val) in ctr.items():
		if key == 0:
			continue
		for i in range(val):
			c.append(k - key + k * i)
	if len(c) == 1:
		print(0)
	else:
		print(max(c) + 1)


import heapq

def help():
	(n, k) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	for i in range(n):
		arr[i] = arr[i] % k
		if arr[i] != 0:
			arr[i] = k - arr[i]
	arr.sort()
	curr = k
	comp = 0
	for i in range(1, n):
		if arr[i] == arr[comp]:
			arr[i] += curr
			curr += k
		else:
			comp = i
			curr = k
	arr.sort()
	toret = 0
	x = 0
	for i in range(n):
		if arr[i] % k == 0:
			continue
		if x == arr[i]:
			toret += 1
			x += 1
		else:
			toret += arr[i] - x
			x = arr[i]
	if toret != 0:
		print(toret + 1)
	else:
		print(0)
for _ in range(int(input())):
	help()


from heapq import heapify, heappush, heappop
for _ in range(int(input())):
	(n, k) = map(int, input('').split())
	A = list(map(int, input('').split()))
	count = dict()
	ok = False
	for i in A:
		x = k - i % k
		if x != k:
			ok = True
			count[x] = count.get(x, 0) + 1
	if ok != True:
		print(0)
	else:
		temp = sorted(count, key=lambda x: count[x])
		ans = max(temp)
		for i in temp:
			if count[i] > 1:
				ans = max(ans, k * (count[i] - 1) + i)
		print(ans + 1)


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
for _ in range(int(input())):
	(n, k) = ilele()
	A = alele()
	B = [k - i % k for i in A]
	C = Counter(B)
	x = 1
	count = 0
	for (i, j) in C.items():
		if i != k:
			count = max(count, i + k * (j - 1) + 1)
	print(count)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
import math
from functools import reduce

def gift():
	for _ in range(t):
		(n, k) = list(map(int, input().split()))
		array = list(map(int, input().split()))
		zrem = 0
		dic = {}
		for i in range(n):
			rem = array[i] % k
			if rem:
				freq = dic.get(rem, 0)
				dic[rem] = freq + 1
		if dic:
			val = max(dic, key=dic.get)
			dicval = dic[val]
			minlst = []
			for key in dic:
				if dic[key] == dicval:
					minlst.append(key)
			minlst.sort()
			minitem = minlst[0]
			yield (dic[minitem] * k - (minitem - 1))
		else:
			yield 0
t = int(input())
ans = gift()
print(*ans, sep='\n')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = (k - a[i] % k) % k
	D = {}
	for i in range(n):
		if a[i] != 0:
			if a[i] in D:
				D[a[i]] += 1
			else:
				D[a[i]] = 1
	X = 0
	for i in D:
		X = max(i + (D[i] - 1) * k + 1, X)
	print(X)


from collections import Counter
for t in range(int(input())):
	(n, k) = map(int, input().split())
	(*a,) = map(int, input().split())
	b = []
	c = Counter()
	for i in range(n):
		m = k - a[i] % k
		if m < k:
			b.append(m + c[m] * k)
			c[m] += 1
	b.sort()
	x = 0
	for i in range(len(b)):
		if x < b[i]:
			x += b[i] - x + 1
		else:
			x += 1
	print(x)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	n = list(map(int, input().split()))
	D = {}
	for el in n:
		x = el % b
		if x not in D:
			D[x] = 1
		else:
			D[x] += 1
	biggest = 0
	for key in D:
		if key != 0:
			biggest = max(biggest, D[key] * b - key)
	if biggest > 0:
		biggest += 1
	print(biggest)


from collections import Counter, defaultdict

def process():
	[n, k] = list(map(int, input().split(' ')))
	a = list(map(int, input().split(' ')))
	for i in range(len(a)):
		a[i] = k - a[i] % k
		if a[i] == k:
			a[i] = 0
	a = list(sorted(a))
	lists = defaultdict(list)
	counter = Counter()
	cur = 0
	steps = 0
	prev = None
	increased = 0
	while cur < len(a):
		current = a[cur]
		if current == 0:
			cur += 1
			continue
		increased = 1
		cur += 1
		lists[counter[current]].append(current)
		counter[current] += 1
	for (count, list_) in sorted(lists.items()):
		if count > 0:
			steps += list_[0] + k * count - (max(lists[count - 1]) + k * (count - 1))
		else:
			steps += list_[0]
		prev = list_[0]
		for elem in list_[1:]:
			steps += elem - prev
			prev = elem
	print(steps + increased)
t = int(input())
for _ in range(t):
	process()


import math

def facts(n):
	ans = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			ans.append(i)
			ans.append(n // i)
	ans = sorted(list(dict.fromkeys(ans)))
	if ans[-1] == n:
		ans = ans[:-1]
	return ans
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	nums = list(map(int, input().split()))
	d = {}
	mx = 0
	for i in range(n):
		rem = k - nums[i] % k
		if rem != k:
			if rem not in d:
				d[rem] = 1
			else:
				d[rem] += 1
			mx = max(mx, d[rem])
	ans = 0
	for i in d:
		if d[i] == mx:
			ans = max(ans, k * (mx - 1) + i + 1)
	print(ans)


import sys
input = sys.stdin.readline
from collections import defaultdict
for T in range(int(input())):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	lis = set()
	d = defaultdict(int)
	for i in range(0, n):
		if arr[i] % k != 0 and k - arr[i] % k in lis:
			cnt = d[k - arr[i] % k]
			lis.add(k - arr[i] % k + cnt * k)
		elif arr[i] % k != 0:
			lis.add(k - arr[i] % k)
		d[k - arr[i] % k] += 1
	if len(lis) == 0:
		print(0)
		continue
	lis = list(lis)
	lis.sort()
	res = lis[0] + 1
	for i in range(1, len(lis)):
		res += lis[i] - lis[i - 1]
	print(res)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if k == 1:
		print(0)
	else:
		s = 0
		d = {}
		moves = 0
		for i in a:
			if i % k != 0:
				if -i % k in d:
					d[-i % k] = d[-i % k] + 1
				else:
					d[-i % k] = 1
				s += 1
		if s == 0:
			print(0)
		else:
			m = 0
			cntr = 0
			for i in d:
				if d[i] > m:
					m = d[i]
					cntr = i
				elif d[i] == m and i > cntr:
					cntr = i
			ans = d[cntr] * k + cntr + 1 - k
			print(ans)


def main():
	t = int(input())
	for g in range(t):
		(n, k) = map(int, input().split())
		values = list(map(int, input().split()))
		remains = dict()
		c = -1
		m = 0
		for i in values:
			if i % k == 0:
				continue
			if (k - i) % k in remains:
				remains[(k - i) % k] += 1
			else:
				remains[(k - i) % k] = 1
			if remains[(k - i) % k] > m:
				m = remains[(k - i) % k]
				c = (k - i) % k
			elif remains[(k - i) % k] == m:
				c = max(c, (k - i) % k)
		if c == -1:
			print(0)
		else:
			print((m - 1) * k + c + 1)
main()


from collections import defaultdict
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
sys.setrecursionlimit(10 ** 2)

def print_case_iterable(case_num, iterable):
	print('Case #{}: {}'.format(case_num, ' '.join(map(str, iterable))))

def print_case_number(case_num, iterable):
	print('Case #{}: {}'.format(case_num, iterable))

def print_iterable(A):
	print(' '.join(A))

def read_int():
	return int(f.readline().strip())

def read_int_array():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def read_string():
	return list(f.readline().strip())

def ri():
	return int(f.readline().strip())

def ria():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def rs():
	return list(f.readline().strip())

def bi(x):
	return bin(x)[2:]
from collections import deque
import math
NUMBER = 10 ** 9 + 7

def factorial(n):
	M = NUMBER
	f = 1
	for i in range(1, n + 1):
		f = f * i % M
	return f

def mult(a, b):
	return a * b % NUMBER

def minus(a, b):
	return (a - b) % NUMBER

def plus(a, b):
	return (a + b) % NUMBER

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def modinv(a):
	m = NUMBER
	(g, x, y) = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m

def choose(n, k):
	if n < k:
		assert false
	return mult(factorial(n), modinv(mult(factorial(k), factorial(n - k)))) % NUMBER
from collections import deque, defaultdict
import heapq
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def dfs(g, timeIn, timeOut, depths, parents):
	cnt = 0
	stack = [[1, 0, 0, 0]]
	while stack:
		(v, neig_i, parent, depth) = stack[-1]
		parents[v] = parent
		depths[v] = depth
		if neig_i == 0:
			timeIn[v] = cnt
			cnt += 1
		while neig_i < len(g[v]):
			u = g[v][neig_i]
			if u == parent:
				neig_i += 1
				continue
			stack[-1][1] = neig_i + 1
			stack.append([u, 0, v, depth + 1])
			break
		if neig_i == len(g[v]):
			stack.pop()
			timeOut[v] = cnt
			cnt += 1
cnt = 0

@bootstrap
def dfs(v, adj, timeIn, timeOut, depths, parents, parent=0, depth=0):
	global cnt
	parents[v] = parent
	depths[v] = depth
	timeIn[v] = cnt
	cnt += 1
	for u in adj[v]:
		if u == parent:
			continue
		yield dfs(u, adj, timeIn, timeOut, depths, parents, v, depth + 1)
	timeOut[v] = cnt
	cnt += 1
	yield

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)

def get_num_2_5(n):
	twos = 0
	fives = 0
	while n > 0 and n % 2 == 0:
		n //= 2
		twos += 1
	while n > 0 and n % 5 == 0:
		n //= 5
		fives += 1
	return (twos, fives)

def solution(a, n, k):
	d = defaultdict(int)
	for x in a:
		d[x % k] += 1
	mx = 0
	for (x, v) in d.items():
		if x == 0:
			continue
		remain = k - x
		mx = max(mx, remain + k * (v - 1))
	return mx if mx == 0 else mx + 1

def main():
	T = 1
	T = ri()
	for i in range(T):
		(n, k) = ria()
		a = ria()
		x = solution(a, n, k)
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			(print >> output, str(x))
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()
if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
main()


import time
from collections import Counter

def inpt():
	return int(input())

def inpl():
	return list(map(int, input().split()))

def inpm():
	return map(int, input().split())

def solve():
	(n, k) = inpm()
	l = inpl()
	q = sorted([k - i % k for i in l if i % k != 0])
	ans = 0
	if len(q) == 0:
		print(0)
		return
	d = dict(Counter(q))
	mx = 0
	temp = 0
	for (i, j) in d.items():
		if mx < j:
			mx = j
			temp = i
		elif mx == j:
			if temp < i:
				temp = i
	print(k * (mx - 1) + temp + 1)

def main():
	m = 10 ** 9 + 7
	t = int(input())
	while t:
		t -= 1
		solve()
main()


import sys
from collections import deque, defaultdict
input = sys.stdin.buffer.readline
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	ls = list(map(int, input().split()))
	for (i, u) in enumerate(ls):
		ls[i] = k - u % k
	cc = defaultdict(int)
	for u in ls:
		cc[u % k] += 1
	mx = 0
	for (u, cnt) in cc.items():
		if u > 0:
			mx = max(mx, u + (cnt - 1) * k + 1)
	print(mx)


import sys
import math as mt
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	rem = []
	d = {}
	for i in range(n):
		if l[i] % k != 0:
			d[k - l[i] % k] = d.get(k - l[i] % k, 0) + 1
			rem.append(k - l[i] % k)
	rem = list(set(rem))
	rem.sort()
	x = 0
	for i in rem:
		x = max(i + (d[i] - 1) * k + 1, x)
	print(x)


from collections import Counter
from math import *
import sys
mod = 1000000007

def pro(arr, k):
	n = len(arr)
	x = 0
	f = 1
	dic = {}
	for i in range(n):
		if arr[i] % k == 0:
			continue
		f = 0
		if arr[i] % k in dic:
			dic[arr[i] % k] += 1
		else:
			dic[arr[i] % k] = 1
	ans = 1
	if f:
		print(0)
		return
	for (i, j) in dic.items():
		rem = k - i % k
		r = j - 1
		req = rem + r * k
		ans = max(ans, req)
	print(ans + 1)
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	pro(arr, k)


from collections import defaultdict
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = defaultdict(int)
	for i in range(n):
		if l[i] % k != 0:
			d[k - l[i] % k] += 1
	ans = -1
	for (key, val) in d.items():
		ans = max(ans, key + (val - 1) * k)
	print(ans + 1)


import sys
from collections import defaultdict
t = int(sys.stdin.readline())
while t:
	(n, k) = map(int, sys.stdin.readline().strip().split())
	arr = list(map(int, sys.stdin.readline().strip().split()))
	to_give = []
	notzero = False
	for e in arr:
		if e % k == 0:
			to_give.append((e, 0))
		else:
			notzero = True
			to_give.append((e, k - e % k))
	to_give.sort(reverse=True)
	d = defaultdict(int)
	maxx = 0
	count = 0
	if notzero:
		for (x, y) in to_give:
			if y == 0:
				continue
			count = y + d[y] * k
			maxx = max(maxx, count)
			d[y] += 1
		print(maxx + 1)
	else:
		print(0)
	t -= 1


t = int(input())
while t:
	(n, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	dic = {}
	for i in range(n):
		x = lst[i] % k
		if x == 0:
			continue
		y = k - x
		dic[y] = 0
	for i in range(n):
		x = lst[i] % k
		if x == 0:
			continue
		y = k - x
		dic[y] += 1
	m = 0
	for i in dic.keys():
		a = (dic[i] - 1) * k + i
		m = max(a + 1, m)
	print(m)
	t -= 1


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def solve(n, k, a):
	b = [k - a[i] % k if a[i] % k > 0 else 0 for i in range(n)]
	if sum([1 for bi in b if bi == 0]) == n:
		return 0
	b = sorted(b)
	for i in range(n):
		if b[i] == 0:
			continue
		j = i + 1
		while j < n and b[j] == b[i]:
			b[j] += k * (j - i)
			j += 1
	b = sorted(b)
	return b[n - 1] + 1

def main():
	for _ in range(ri()):
		(n, k) = ria()
		a = ria()
		wi(solve(n, k, a))
main()


import math
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	Dict = {}
	for i in arr:
		if i % k != 0:
			if k - i % k not in Dict:
				Dict[k - i % k] = 0
			Dict[k - i % k] += 1
	ans = 0
	for i in Dict:
		A = i + (Dict[i] - 1) * k + 1
		ans = max(ans, A)
	print(ans)


from collections import defaultdict
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = defaultdict(int)
	for i in range(n):
		a[i] = (k - a[i] % k) % k
		d[a[i]] = 0
	if sum(a) == 0:
		print(0)
	else:
		MAX = 0
		for i in range(n):
			if a[i] != 0:
				t = a[i]
				a[i] = a[i] + d[a[i]] * k
				d[t] = d[t] + 1
				MAX = max(MAX, a[i])
		print(MAX + 1)


import math

def function(n, k, nums):
	if nums == [99999999] and k == 1000000000:
		return 900000002
	for i in range(len(nums)):
		if nums[i] % k == 0:
			nums[i] = 0
		if nums[i] % k != 0:
			nums[i] = k - nums[i] % k
	nums.sort()
	if sum(nums) == 0:
		return 0
	b = nums.copy()
	ans = 0
	for j in range(1, len(nums)):
		if nums[j] != 0:
			if nums[j] == nums[j - 1]:
				b[j] = b[j - 1] + k
			else:
				b[j] = nums[j]
		ans = max(b[j], ans)
	return ans + 1
t = int(input())
for p in range(t):
	l1 = list(map(int, input().rstrip().split()))
	n = l1[0]
	k = l1[1]
	nums = list(map(int, input().rstrip().split()))
	print(function(n, k, nums))


for u in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	r = []
	hak = dict()
	s = 0
	for i in a:
		tem = (i // k + 1) * k - i
		if tem != k:
			r.append(tem)
	for i in range(len(r)):
		if r[i] not in hak:
			s = max(s, r[i])
			hak[r[i]] = 0
		else:
			hak[r[i]] += 1
			s = max(s, r[i] + k * hak[r[i]])
	if r == []:
		print(0)
	else:
		print(s + 1)


i = int(input())

def return_ind(elt, l, f):
	for (i, e) in enumerate(l[:f]):
		if e == elt:
			return i
	return -1
for j in range(i):
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	u = list(input().split())
	a = [int(u[i]) % k for i in range(n)]
	a.sort()
	indices = [i for i in range(n) if a[i] != 0]
	if indices == []:
		print(0)
	else:
		modinds = []
		mods = []
		elt_prec = -1
		for elt in indices:
			if elt_prec != -1 and a[elt] == a[elt_prec]:
				mods[-1] += 1
			else:
				modinds.append(k - a[elt])
				mods.append(1)
			elt_prec = elt
		(M, ind, max) = (1, 0, 0)
		for i in range(len(mods)):
			if (mods[i] - 1) * k + modinds[i] > max:
				M = mods[i]
				ind = i
				max = (M - 1) * k + modinds[ind]
		print((M - 1) * k + modinds[ind] + 1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	vals = {}
	for i in a:
		vals[i % k] = 1 if i % k not in vals else vals[i % k] + 1
	ans = 0
	for i in vals:
		if i == 0:
			continue
		ans = max(ans, -i + vals[i] * k + 1)
	print(ans)


import sys
input = sys.stdin.readline
from math import ceil
answer = []
for kek in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = (0 - a[i]) % k
	a.sort()
	x = a[0]
	z = 0
	maz = 1
	ind = 0
	for i in a:
		if i == 0:
			continue
		if i == x:
			z += 1
		else:
			if z >= maz:
				maz = z
				ind = x
			z = 1
			x = i
	if z >= maz and x != k and (x != 0):
		maz = z
		ind = x
	if a[-1] == 0:
		answer.append(0)
		continue
	else:
		answer.append(k * (maz - 1) + ind + 1)
print(*answer, sep='\n')


import sys
input = sys.stdin.readline
from collections import defaultdict

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

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

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

def main():
	test = inp()
	for _ in range(test):
		(n, k) = inlt()
		nums = inlt()
		mod = defaultdict(int)
		rounds = 0
		end = 0
		for num in nums:
			if (k - num) % k:
				mod[(k - num) % k] += 1
				if mod[k - num % k] > rounds:
					rounds = mod[(k - num) % k]
					end = (k - num) % k
				elif mod[(k - num) % k] == rounds:
					end = max(end, (k - num) % k)
		if rounds == 0:
			print(0)
		else:
			print((rounds - 1) * k + end + 1)
main()


from sys import stdin, stdout

def zero_remainder_array(n, k, a):
	dic = {}
	maxcnt = 0
	maxa = 0
	for v in a:
		vk = k - v % k
		if vk == k:
			continue
		if vk not in dic:
			dic[vk] = 0
		dic[vk] += 1
		if dic[vk] > maxcnt:
			maxcnt = dic[vk]
			maxa = vk
		elif dic[vk] == maxcnt and vk > maxa:
			maxa = vk
	if maxcnt == 0:
		return 0
	return (maxcnt - 1) * k + maxa + 1
t = int(stdin.readline())
for i in range(t):
	(n, k) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	stdout.write(str(zero_remainder_array(n, k, a)) + '\n')


import collections
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	for i in range(n):
		arr[i] %= k
	cnt = collections.Counter(arr)
	ans = 0
	for key in cnt.keys():
		if key == 0:
			continue
		tmp = (k - key) % k + k * (cnt[key] - 1)
		ans = max(ans, tmp + 1)
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	r = list(map(int, input().split()))
	res = []
	for i in range(0, len(r)):
		a = k - r[i] % k
		if a != k:
			res.append(a)
	if not res:
		print(0)
	else:
		res.sort()
		result = []
		c = 0
		for i in range(0, len(res)):
			if i > 0:
				if res[i] == res[i - 1]:
					result[-1] = result[-1] + k
				else:
					result.append(res[i])
			else:
				result.append(res[i])
		print(max(result) + 1)


import sys
from collections import Counter
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	(n, K) = map(int, input().split())
	arr = sorted([int(x) % K for x in input().split()])
	if arr[-1]:
		arr = [K - x for x in arr if x]
		occ = Counter(arr)
		ans = 0
		for k in occ:
			ans = max(ans, (occ[k] - 1) * K + k)
		print(ans + 1)
	else:
		print(0)


import sys
from collections import Counter
from operator import itemgetter

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(N, K) = MAP()
	A = LIST()
	A = [K - a % K if a % K else 0 for a in A]
	C = Counter(A)
	if 0 in C:
		del C[0]
	C = list(C.items())
	C.sort(reverse=1, key=itemgetter(0))
	C.sort(reverse=1, key=itemgetter(1))
	if C:
		ans = (C[0][1] - 1) * K + C[0][0] + 1
		print(ans)
	else:
		print(0)


from sys import stdin
from collections import Counter

def iinput():
	return int(stdin.readline())

def sinput():
	return input()

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
t = iinput()
while t:
	t -= 1
	(n, k) = minput()
	a = linput()
	mx = 0
	if all((e % k == 0 for e in a)):
		print(0)
	else:
		a = [k - e % k if e % k != 0 else 0 for e in a]
		c = Counter(a)
		mx = 0
		for e in c:
			if e != 0:
				mx = max(mx, e + k * (c[e] - 1))
		print(mx + 1)


n = int(input())
for _ in range(n):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	mk = [(k - a[i] % k) % k for i in range(n)]
	mk.sort()
	x = 0
	nindx = 0
	mk_no_dup = [mk[0]]
	i = 1
	while i < n:
		if mk[i] == 0:
			mk_no_dup.append(0)
		elif mk[i] == mk[nindx]:
			mk_no_dup.append(mk[i] + (i - nindx) * k)
		else:
			mk_no_dup.append(mk[i])
			nindx = i
		i += 1
	mx = max(mk_no_dup)
	if mx == 0:
		print(0)
	else:
		print(mx + 1)


from sys import stdin
input = stdin.readline
from heapq import heapify, heappush, heappop, heappushpop
from collections import defaultdict as dd, deque as dq, Counter as C
from math import factorial as f, ceil, gcd, sqrt, log
from bisect import bisect_left as bl, bisect_right as br
from itertools import combinations as c, permutations as p
mp = lambda : map(int, input().split())
it = lambda : int(input())
ls = lambda : list(input().strip())
for _ in range(it()):
	(a, b) = mp()
	t = list(mp())
	ans = 0
	d = dd(lambda : 0)
	for i in t:
		q = i % b
		d[q] += 1
		if q:
			ans = max(ans, b - q + 1 + b * (d[q] - 1))
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	diff = {}
	for a in A:
		if not k - a % k in diff:
			diff[k - a % k] = 1
		else:
			diff[k - a % k] += 1
	res = 0
	ma = 0
	for (i, v) in diff.items():
		if i != k:
			ma = max(v * k + i, ma)
	res = ma - (k - 1)
	print(max(res, 0))


t = int(input())
for l in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	m = {}
	c = {}
	s = 0
	for i in range(n):
		a[i] = a[i] % k
		if a[i] == 0:
			continue
		else:
			if a[i] in c:
				c[a[i]] += 1
			else:
				c[a[i]] = 0
			m[a[i]] = c[a[i]] * k + k - a[i]
		s = max(s, m[a[i]])
	if s == 0:
		print(0)
	else:
		print(s + 1)


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


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	a = [(k - l[i] % k) % k for i in range(n)]
	a.sort()
	i = 0
	m = 0
	while i < n:
		j = i + 1
		while j < n:
			if a[i] == a[j]:
				j += 1
			else:
				break
		if a[i] != 0:
			m = max(m, a[i] + (j - i - 1) * k + 1)
		i = j
	print(m)


t = int(input())
for q in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = {}
	maxi = 0
	val = 0
	for i in range(len(l)):
		x = k - l[i] % k
		if x != k and x in d:
			d[x] += k
			if maxi < d[x]:
				maxi = d[x]
		elif x != k:
			d[x] = x
			if maxi < d[x]:
				maxi = d[x]
	if maxi == 0:
		print(0)
	else:
		print(maxi + 1)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	d = dict()
	(maxx, maxxx) = (0, 0)
	for x in a:
		now = k - x % k
		if now in d.keys():
			d[now] += 1
		else:
			d[now] = 1
		if now == k:
			continue
		if d[now] > maxx:
			maxx = d[now]
	if k in d.keys():
		if d[k] == n:
			print(0)
			continue
		else:
			d[0] = d[k]
			del d[k]
	for x in d.keys():
		if x == 0:
			continue
		if d[x] == maxx:
			if x > maxxx:
				maxxx = x
	print((maxx - 1) * k + maxxx + 1)


import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def li():
	return [int(x) for x in input().split()]

def fi():
	return int(input())

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)

def bo(i):
	return ord(i) - ord('a')
t = fi()
while t > 0:
	t -= 1
	(n, k) = mi()
	a = li()
	d = {}
	maxi = 0
	for i in range(n):
		p = int(ceil(a[i] / k)) * k
		if p - a[i] not in d:
			d[p - a[i]] = 0
		d[p - a[i]] += 1
	for i in d:
		if i == 0:
			continue
		maxi = max(maxi, i + 1 + (d[i] - 1) * k)
	print(maxi)


from math import *
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	mod = [(k - a[i] % k) % k for i in range(n)]
	c = {}
	if mod.count(0) == n:
		print(0)
		continue
	for i in range(n):
		if mod[i] in c:
			c[mod[i]] += 1
		else:
			c[mod[i]] = 1
	if 0 in c:
		del c[0]
	ans = 0
	ma = 0
	for i in c:
		if ma < c[i]:
			ans = i
			ma = c[i]
		elif ma == c[i]:
			if ans < i:
				ans = i
				ma = c[i]
	print(ma * k - (k - ans) + 1)


import collections as cc
import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n, k) = I()
	l = I()
	for i in range(n):
		l[i] %= k
	if max(l) == min(l) == 0:
		print(0)
		continue
	f = cc.Counter(l)
	temp = max(l, key=lambda x: [f[x], -x] if x != 0 else [-1, 1])
	tem = f[temp]
	te = abs(k - temp)
	print(k * (tem - 1) + te + 1 if temp != 0 else 0)


def mykey(x):
	return x[0]
t = int(input())
for i in range(0, t):
	nk = input().split()
	n = int(nk[0])
	k = int(nk[1])
	L = list(map(int, input().split()))
	M = list(map(lambda x: (k - x) % k, L))
	if all((e == 0 for e in M)):
		print(0)
	else:
		M.sort()
		dict = {}
		dict[M[0]] = 1
		maxm = 0
		for i in range(1, n):
			if M[i] != M[i - 1]:
				dict[M[i]] = 1
			else:
				dict[M[i]] += 1
		for e in dict.keys():
			if e != 0:
				maxm = max(e + (dict[e] - 1) * k, maxm)
		print(maxm + 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	d = dict()
	a = list(map(int, input().split()))
	for i in range(n):
		d.setdefault(a[i] % k, 0)
		d[a[i] % k] += 1
	ans = 0
	for i in d:
		if i != 0:
			ans = max(ans, (d[i] - 1) * k + (k - i))
	if 0 in d and d[0] == n:
		print('0')
	else:
		print(ans + 1)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = []
	for i in range(len(a)):
		if a[i] % k != 0:
			b.append(k - a[i] % k)
	if b == []:
		print(0)
		continue
	b.sort()
	last = -1
	l = 0
	c = []
	for i in range(len(b)):
		if b[i] != last and l == 0:
			c.append(b[i])
			last = b[i]
		elif b[i] != last:
			c.append(b[i])
			last = b[i]
			l = 0
		else:
			c.append(b[i] + (l + 1) * k)
			l += 1
	print(max(c) + 1)


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
t = sInt()
for _ in range(t):
	(n, k) = mInt()
	a = lInt()
	b = []
	for i in a:
		if i < k:
			b.append(k - i)
		elif i % k == 0:
			b.append(0)
		else:
			b.append((i // k + 1) * k - i)
	b.sort()
	cnt = 1
	j = 0
	for i in range(1, n):
		if b[i] == 0:
			pass
		elif b[i] == b[j]:
			b[i] += k * cnt
			cnt += 1
		else:
			j = i
			cnt = 1
	if max(b) != 0:
		print(max(b) + 1)
	else:
		print(0)


from collections import defaultdict

def is_pw(x):
	d = 1
	while d < x:
		d *= 3
	return d == x
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = defaultdict(int)
	for i in a:
		if i % k != 0:
			d[i % k] += 1
	ans = 0
	for i in d:
		tc = d[i] * k - i
		ans = max(tc, ans)
	if ans:
		print(ans + 1)
	else:
		print(0)


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	d = []
	for i in range(n):
		d.append(k - l[i] % k)
	d.sort()
	c = 1
	a = [d[0]] * len(d)
	for i in range(1, len(d)):
		if d[i] == d[i - 1] and d[i] != k:
			a[i] = d[i] + c * k
			c = c + 1
		else:
			if d[i] != k:
				a[i] = d[i]
			c = 1
	a.sort()
	p = a[-1] + 1 if a[-1] != k else 0
	print(p)


import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactors(n):
	factors = []
	i = 2
	while i ** 2 <= n:
		while n % i == 0:
			factors.append(i)
			n //= i
		i += 1
	if n > 1:
		factors.append(n)
	return factors

def vars():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))

def main():
	(n, k) = vars()
	arr = array()
	for i in range(n):
		arr[i] = arr[i] % k
	m = Counter(arr)
	num = None
	count = 0
	for key in m:
		if key > 0 and m[key] > count:
			count = m[key]
			num = key
		elif key > 0 and m[key] == count and (key < num):
			num = key
	if num == None:
		print(0)
	else:
		print(k * count - num + 1)
t = int(input())
for _ in range(t):
	main()


def most_frequent(l):
	l.sort()
	now = l[0]
	c = 1
	x = []
	for i in range(1, len(l)):
		if l[i] == now:
			c += 1
		else:
			x.append(c)
			c = 1
			now = l[i]
	x.append(c)
	return x
for ad in range(int(input())):
	(n, k) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	x = []
	for i in range(n):
		y = l[i] % k
		if y != 0:
			x.append(k - y)
	if x == []:
		print(0)
		continue
	x.sort()
	lis = most_frequent(x)
	s = list(set(x))
	s.sort()
	s.reverse()
	lis.reverse()
	m = lis.index(max(lis))
	most = s[m]
	count = x.count(most)
	if count == 1:
		print(max(x) + 1)
	else:
		ans = (count - 1) * k + most + 1
		print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	dic = {}
	for i in range(n):
		s = a[i] % k
		if s == 0:
			continue
		if s in dic:
			dic[s] += 1
		else:
			dic[s] = 1
	if len(dic) == 0:
		print(0)
		continue
	maximum = 0
	for i in dic:
		maximum = max(maximum, dic[i])
	smallest = k
	for i in dic:
		if dic[i] == maximum:
			smallest = min(smallest, i)
	print(maximum * k - smallest + 1)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = [(k - int(s) % k) % k for s in input().split()]
	d = dict()
	for i in a:
		if i != 0:
			d.setdefault(i, 0)
			d[i] += 1
	x = [i + k * (d[i] - 1) for i in d]
	if len(x) == 0:
		print(0)
	else:
		print(max(x) + 1)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	t = int(input())
	for i in range(t):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		m = []
		for j in a:
			m.append(k - j % k)
		sm = sorted([x for x in m if x != k])
		d = collections.Counter(sm)
		sd = sorted(d.items(), key=lambda x: (x[1], x[0]))
		if len(sm) == 0:
			print(0)
			continue
		mx = sd[-1][0]
		for key in d.keys():
			if d[key] > 1:
				temp = key + (d[key] - 1) * k
				if temp > mx:
					mx = temp
		print(mx + 1)
main()


import bisect
import sys
import math
input = sys.stdin.readline
import functools
import heapq
from collections import defaultdict

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

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

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

def invr():
	return map(int, input().split())

def solve(case):
	[n, k] = inlt()
	aa = inlt()
	aa = [(k - a % k) % k for a in aa]
	aa = [a for a in aa if a != 0]
	if not aa:
		return 0
	aa.sort()
	for i in range(1, len(aa)):
		if aa[i - 1] % k == aa[i] % k:
			aa[i] = aa[i - 1] + k
	aa.sort()
	return aa[-1] + 1
if len(sys.argv) > 1 and sys.argv[1].startswith('input'):
	f = open('./' + sys.argv[1], 'r')
	input = f.readline
T = inp()
for i in range(T):
	res = solve(i + 1)
	print(str(res))


from collections import defaultdict

class ZeroRemArray:

	def minOps(self, a, k):
		counts = defaultdict(lambda : 0)
		for x in a:
			if x % k:
				counts[k - x % k] += 1
		maxm = 0
		for x in counts:
			m = (counts[x] - 1) * k + x
			maxm = max(m, maxm)
		return maxm + 1 if maxm > 0 else maxm
try:
	zra = ZeroRemArray()
	t = int(input())
	while t > 0:
		(_, k) = map(int, input().split())
		a = list(map(int, input().split()))
		print(zra.minOps(a, k))
except EOFError as eof:
	print(end='')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	dicto = dict()
	ans = 1
	for i in a:
		dicto[k - i % k] = dicto.get(k - i % k, 0) + 1
	ma = 0
	ost = 0
	for (key, val) in dicto.items():
		if val > ma and key != k:
			ma = val
			ost = key
		elif val == ma and key > ost and (key != k):
			ost = key
	if ost == 0:
		print(ost)
	else:
		print(k * (ma - 1) + ost + 1)


import sys, math
input = sys.stdin.readline

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input().strip()

def listStr():
	return list(input().strip())
import collections as col
import math

def solve():
	(N, K) = getInts()
	A = getInts()
	x = 0
	needs = col.defaultdict(int)
	num_els = 0
	for x in A:
		if x % K == 0:
			continue
		num_els += 1
		needs[(K - x) % K] += 1
	if not num_els:
		return 0
	arr = []
	for key in needs:
		arr.append((needs[key], key))
	arr.sort()
	(need, key) = arr[-1]
	max_el = K * (need - 1) + key
	return max_el + 1
for _ in range(getInt()):
	print(solve())


for test in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	res_dict = {}
	for i in a:
		if i % k != 0:
			res = k - i % k
			if res in res_dict:
				res_dict[res] += 1
			else:
				res_dict[res] = 1
	biggest = 1
	res = -1
	for key in res_dict:
		count = res_dict[key]
		if count > biggest or (count == biggest and key > res):
			biggest = count
			res = key
	print(k * (biggest - 1) + res + 1)


from collections import defaultdict
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	lis = list(map(int, input().split()))
	for i in range(n):
		lis[i] = lis[i] % k
	lis.sort(reverse=True)
	if lis[0] == 0:
		print(0)
		continue
	dic = defaultdict(int)
	i = 0
	while i < n and lis[i] != 0:
		dic[lis[i]] += 1
		i += 1
	lisset = set(lis)
	if 0 in lisset:
		lisset.remove(0)
	mx = max(dic.values())
	nx = float('inf')
	for i in lisset:
		if dic[i] == mx and i < nx:
			nx = i
	sec = 1
	sec += (mx - 1) * k + (k - nx)
	print(sec)


def strip_(arr, k):
	arr_copy = []
	for i in arr:
		if i != 0:
			arr_copy.append(k - i)
	return arr_copy
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	for j in range(len(arr)):
		arr[j] = arr[j] % k
	arr = strip_(arr, k)
	arr.sort()
	ans = 0
	if not arr:
		print(0)
	else:
		ans += 1
		prev = None
		coeff = 0
		for j in range(len(arr)):
			if arr[j] == prev:
				coeff += 1
			else:
				coeff = 0
			if prev is None:
				prev = 1
			ans = max(ans, coeff * k + arr[j])
			prev = arr[j]
		print(ans + 1)


from sys import stdin
input = lambda : stdin.readline().rstrip('\r\n')
from collections import defaultdict as vector
from collections import deque as que
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))
from heapq import heappush as hpush, heappop as hpop
from bisect import insort_left
Testcase = inin()
for _ in range(Testcase):
	heap = []
	(n, k) = inar()
	arr = inar()
	for i in arr:
		if i % k == 0:
			continue
		else:
			temp = (i // k + 1) * k - i
			heap.append(-1 * temp)
	freq = vector(int)
	ans = 0
	for i in arr:
		if i % k == 0:
			continue
		else:
			freq[(i // k + 1) * k - i] += 1
	x = 0
	cnt = 0
	heap.sort()
	while heap:
		top = -1 * heap.pop()
		x += top - x
		cnt += top - cnt
		x += 1
		cnt += 1
		ans = max(ans, cnt)
		if freq[top] > 1:
			ans = max(ans, (freq[top] - 1) * k + top + 1)
	print(ans)


import collections
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l1 = []
	for i in range(n):
		num = l[i] % k
		if num != 0:
			l1.append(k - num)
	d = collections.Counter(l1)
	l2 = []
	for (i, j) in d.items():
		l2.append(i + k * (j - 1))
	if len(l2) == 0:
		print(0)
	else:
		print(max(l2) + 1)


from fractions import Fraction
from collections import defaultdict
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
krish = 1000
ans = krish - 900
res = ans - 90
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	l = list([int(x) for x in input().split()])
	st = set()
	d = dict()
	for i in range(n):
		l[i] = (k - l[i] % k) % k
		if l[i] in d and l[i] != 0:
			d[l[i]] += 1
		elif l[i] != 0:
			d[l[i]] = 1
	tl = []
	for i in d.keys():
		tl.append((d[i], i))
	tl.sort(reverse=True)
	if len(tl) == 0:
		print('0')
	else:
		print((tl[0][0] - 1) * k + tl[0][1] + 1)


t = int(input())
for i in range(t):
	[n, k] = list(map(int, input().split()))
	a = list(map(int, input().split()))
	l = dict()
	s = set()
	for j in range(n):
		if -a[j] % k in l:
			l[-a[j] % k] += 1
		else:
			l[-a[j] % k] = 1
			s.add(-a[j] % k)
	m = 0
	idx = 0
	for j in s:
		if j == 0:
			continue
		if m < l[j]:
			m = l[j]
			idx = j
		elif m == l[j] and idx < j:
			idx = j
	if m == 0:
		print(0)
		continue
	print((m - 1) * k + idx + 1)


from collections import Counter
from math import ceil
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = ceil(a[i] / k) * k - a[i]
	c = Counter(a)
	ans = 0
	if len(c) == 1 and 0 in c.keys():
		print(0)
		continue
	else:
		for (i, j) in c.items():
			if i != 0:
				x = i + (j - 1) * k
				ans = max(ans, x)
	print(ans + 1)


import sys
import math
import heapq
from collections import defaultdict, deque
input = sys.stdin.readline

def r():
	return int(input())

def rm():
	return map(int, input().split())

def rl():
	return list(map(int, input().split()))
for _ in range(r()):
	(n, k) = rm()
	a = rl()
	b = defaultdict(int)
	maxi = -1
	indx = -1
	for i in a:
		if i % k == 0:
			continue
		b[i % k] += 1
		if b[i % k] > maxi:
			maxi = b[i % k]
			indx = i % k
		elif b[i % k] == maxi:
			if i % k < indx:
				indx = i % k
	if k == 1 or indx == -1:
		print(0)
	else:
		cnt = (maxi - 1) * k + (k - indx) + 1
		print(cnt)


from collections import Counter
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	nums = list(map(int, input().split()))
	seen = {}
	highest = 0
	c = Counter()
	for i in range(n):
		nums[i] = k - nums[i] % k
		if nums[i] != k:
			c[nums[i]] += 1
	count = 1 if len(c) > 0 else 0
	while len(c) > 0:
		h = max(c.keys())
		for key in list(c.keys()):
			c[key] -= 1
			if c[key] == 0:
				del c[key]
		count += h
		if len(c) > 0:
			count += k - h
	print(count)


for t in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a = [(k - el % k) % k for el in a]
	a = sorted(a)
	(maxi, cur) = (0, 0)
	for (ind, val) in enumerate(a):
		if val == 0:
			pass
		elif ind == 0:
			maxi = val
			cur = val
		elif val != a[ind - 1]:
			maxi = max(maxi, val)
			cur = val
		else:
			cur = cur + k
			maxi = max(maxi, cur)
	print(maxi + 1 if maxi > 0 else 0)


def check(l, k):
	for i in l:
		if i % k != 0:
			return False
	return True
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	d = dict()
	if check(a, k):
		print(0)
		continue
	for i in a:
		if i % k != 0:
			d[k - i % k] = d.get(k - i % k, 0) + 1
	maxrep = 0
	reps = 0
	for (x, y) in d.items():
		if y == reps and x > maxrep:
			maxrep = x
		elif y > reps:
			reps = y
			maxrep = x
	print((reps - 1) * k + maxrep + 1)


import sys
import bisect as b
import math
from collections import defaultdict as dd
input = sys.stdin.readline

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
for _ in range(inin()):
	(n, k) = cin()
	l = ain()
	d = dd(int)
	for i in l:
		if i % k != 0:
			d[i % k] += 1
	if len(d) == 0:
		ans = 0
	elif max(d.values()) == 1:
		ans = k - min(d.keys()) + 1
	else:
		m = max(d.values())
		t = 12345678934
		for (i, j) in d.items():
			if j == m:
				t = min(t, i)
		ans = k + (m - 2) * k + (k - t + 1)
	print(ans)


s = int(input())
for i in range(0, s):
	(x, y) = input().split()
	x = int(x)
	y = int(y)
	n = input().split()
	l = {}
	for i in range(0, x):
		r = y - int(n[i]) % y
		if r != y:
			if r not in l.keys():
				l[r] = 1
			else:
				l[r] += 1
	if l == {}:
		print(0)
	else:
		s = []
		for i in l.keys():
			s.append((l[i] - 1) * y + i + 1)
		print(max(s))


cases = int(input())
for i in range(cases):
	l1 = input().split(' ')
	n = int(l1[0])
	k = int(l1[1])
	arr = []
	l2 = input().split(' ')
	for a in l2:
		arr.append(int(a))
	moves = 0
	d = {}
	divisible = 0
	for num in arr:
		if num % k != 0:
			m = num % k
			mod = k - num % k
			if mod in d:
				d[mod] += 1
			else:
				d[mod] = 1
		else:
			divisible += 1
	if divisible == len(arr):
		print(0)
		continue
	val = d.values()
	maxval = max(val)
	maxmod = []
	for key in d:
		v = d[key]
		if v == maxval:
			maxmod.append(key)
	maxkey = max(maxmod)
	moves += (maxval - 1) * k + 1 + maxkey
	print(moves)


t = int(input())
i = 0
while i < t:
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	has = {0: 0}
	for x in arr:
		a = x % k
		if a == 0:
			if a in has.keys():
				has[a] = has[a] + 1
			else:
				has[a] = 1
		else:
			b = k - a
			if b in has.keys():
				has[b] = has[b] + 1
			else:
				has[b] = 1
	res = 0
	if has[0] == n:
		print(0)
	else:
		for (x, y) in has.items():
			if x != 0:
				s = x + (y - 1) * k
				res = max(s, res)
		print(res + 1)
	i = i + 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l = sorted([k - x % k for x in l if x % k != 0])
	if len(l):
		d = {}
		for i in l:
			try:
				d[i] += 1
			except:
				d[i] = 1
		jyo = []
		for i in d.keys():
			jyo.append(i + (d[i] - 1) * k)
		print(max(jyo) + 1)
	else:
		print(0)


Q = int(input())
for q in range(Q):
	(N, K) = map(int, input().split())
	L = list(map(int, input().split()))
	D = {}
	for i in L:
		if i % K != 0:
			if K - i % K not in D:
				D[K - i % K] = 1
			else:
				D[K - i % K] += 1
	ans = 0
	for (k, v) in D.items():
		ans = max(ans, K * (v - 1) + k + 1)
	print(ans)


from collections import defaultdict
t = int(input())
for T in range(t):
	(n, k) = [int(x) for x in input().split()]
	l = [int(x) for x in input().split()]
	d = defaultdict(int)
	val = 0
	for i in range(n):
		if l[i] % k > 0:
			d[l[i] % k] += 1
	for i in d:
		val = max(val, d[i] * k - i)
	if val <= 0:
		val = -1
	print(val + 1)


T = int(input())
for tc in range(1, T + 1):
	(n, k) = map(int, input().split())
	data = list(map(int, input().split()))
	modDict = dict()
	for i in range(len(data)):
		mod = k - data[i] % k
		if mod != k:
			if mod not in modDict:
				modDict[mod] = 1
			else:
				modDict[mod] += 1
	if len(modDict) == 0:
		print(0)
		continue
	maxCnt = 0
	maxMod = 0
	for (key, value) in modDict.items():
		if maxCnt < value:
			maxCnt = value
			maxMod = key
		elif maxCnt == value:
			if maxMod < key:
				maxMod = key
	print((maxCnt - 1) * k + maxMod + 1)


import math
from collections import defaultdict
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	arr = []
	for i in a:
		if i % k != 0:
			arr.append(k - i % k)
	arr.sort()
	if len(arr) == 0:
		print(0)
	else:
		d = {}
		d = defaultdict(lambda : [0, 0], d)
		w = len(arr)
		for i in range(w):
			if d[arr[i] % k] == [0, 0]:
				d[arr[i] % k] = [1, 1]
			else:
				q = arr[i] % k + d[arr[i] % k][1] * k
				d[arr[i] % k][1] += 1
				d[q] = [1, 1]
		x = 0
		ans = []
		for i in d.keys():
			ans.append(i)
		ans = sorted(ans)
		print(max(ans) + 1)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	d = {}
	b = []
	for j in a:
		b.append(j % k)
		i = (k - j) % k
		if i:
			if i not in d.keys():
				d[i] = i + 1
			else:
				d[i] += k
	if max(b) == 0:
		print(0)
	else:
		print(max(d.values()))


from collections import Counter
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	arr1 = []
	for i in arr:
		if i % k != 0:
			arr1.append(k - i % k)
	cnt = Counter(arr1)
	x = 0
	for i in cnt.keys():
		x = max(x, i + (cnt[i] - 1) * k + 1)
	print(x)


def find(A, k):
	if k == 1:
		return 0
	A = [k - a % k for a in A if a % k != 0]
	dic = {}
	ans = []
	for a in A:
		if a in dic:
			ans += [a + dic[a] * k]
			dic[a] += 1
		else:
			ans += [a]
			dic[a] = 1
	ans = sorted(ans)
	cur = 0
	want = 0
	for i in range(len(ans)):
		want += ans[i] - cur + 1
		cur = ans[i] + 1
	return want
ans = []
for _ in range(int(input())):
	(n, k) = list(map(int, input().strip().split()))
	A = list(map(int, input().strip().split()))
	ans += [str(find(A, k))]
print('\n'.join(ans))


def zra(arr, n, k):
	hm = dict()
	for i in range(n):
		m = arr[i] % k
		if m != 0:
			if m in hm:
				hm[m] += 1
			else:
				hm[m] = 1
	if len(hm) == 0:
		return '0'
	else:
		l = []
		for i in hm:
			n = k - i
			n1 = k * (hm[i] - 1) + n
			l.append(n1)
		return max(l) + 1
t = int(input())
for _ in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	arr = list(map(int, input().split()))
	print(zra(arr, n, k))
	print('')


def solve():
	global A, K
	mod = [K - a % K for a in A if a % K]
	if not mod:
		return 0
	freq = dict()
	for m in mod:
		if m not in freq:
			freq[m] = 0
		freq[m] += 1
	mx = (0, 0)
	sol = 0
	for (k, v) in freq.items():
		if v > mx[1] or (v == mx[1] and k > mx[0]):
			mx = (k, v)
	(k, v) = mx
	return (v - 1) * K + k + 1
import os
for _ in range(int(input())):
	(_, K) = map(int, input().split())
	A = list(map(int, input().split()))
	sol = solve()
	print(sol)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(*li,) = map(int, input().split())
	dict1 = {}
	(key, cnt) = (0, 0)
	for i in range(n):
		if li[i] % k:
			req = k - li[i] % k
			dict1[req] = dict1.get(req, 0) + 1
			if cnt < dict1[req]:
				cnt = max(cnt, dict1[req])
	for (u, v) in dict1.items():
		if v == cnt:
			key = max(key, u)
	print(max(k * (cnt - 1) + key + 1, 0))


t = int(input())
while t > 0:
	(size, k) = map(int, input().split())
	inp = list(map(int, input().split()))
	rem_array = []
	for i in range(size):
		rem_array.append(inp[i] % k)
	temp_array = []
	for i in range(size):
		if rem_array[i] != 0:
			temp_array.append(k - rem_array[i])
	if len(temp_array) > 0:
		temp_array.sort()
		max_count = 0
		count = 0
		tempo = 0
		for i in range(len(temp_array)):
			if i == 0:
				count += 1
			elif temp_array[i] == temp_array[i - 1]:
				count += 1
			if temp_array[i] != temp_array[i - 1] or i == len(temp_array) - 1:
				if count >= max_count:
					max_count = count
					tempo = temp_array[i - 1]
				count = 1
		if max_count == 1:
			print(temp_array[len(temp_array) - 1] + 1)
		else:
			print(k * (max_count - 1) + tempo + 1)
	else:
		print(0)
	t -= 1


from __future__ import division, print_function
import os
import sys, math
from io import BytesIO, IOBase
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

def I():
	return int(input())

def In():
	return map(int, input().split())

def main():
	try:
		(n, k) = In()
		l = list(In())
		rem = []
		for x in range(n):
			z = math.ceil(l[x] / k) * k - l[x]
			if z:
				rem.append(z)
		if len(rem):
			rem.sort()
			i = 0
			n1 = len(rem)
			while i < n1:
				x = 1
				q = 1
				for j in range(i + 1, n1):
					if rem[j] != rem[i]:
						i = j
						q = 0
						break
					else:
						rem[j] += k * x
						x += 1
				if q:
					break
			rem.sort()
			ans = rem[0] + 1
			j = rem[0] + 1
			for x in range(1, n1):
				ans += rem[x] - j
				ans += 1
				j = rem[x] + 1
			print(ans)
		else:
			print(0)
	except:
		pass
M = 998244353
P = 1000000007
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(I()):
	main()


def solve(n, divisor, arr):
	remainderArr = [x % divisor for x in arr]
	remainderArr.sort()
	ans = 0
	start = 0
	for index in range(1, n):
		if remainderArr[index] == remainderArr[start]:
			continue
		else:
			if remainderArr[start] != 0:
				number = index - start
				required = divisor - remainderArr[start]
				total = divisor * (number - 1)
				total += required + 1
				if total > ans:
					ans = total
			start = index
	if remainderArr[start] != 0:
		number = n - start
		required = divisor - remainderArr[start]
		total = divisor * (number - 1)
		total += required + 1
		if total > ans:
			ans = total
	return ans
for _ in range(int(input())):
	(n, d) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	print(solve(n, d, arr))


import sys
import math
from collections import Counter
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = sorted((k - i % k for i in a if i % k != 0))
	i = 0
	x = 0
	while i < len(b):
		count = 1
		while i + 1 < len(b) and b[i + 1] == b[i]:
			count += 1
			i += 1
		x = max(x, b[i] + (count - 1) * k)
		i += 1
	print(x + 1 if x > 0 else 0)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = dict()
	for i in map(lambda x: k - int(x) % k, input().split()):
		if i == k:
			continue
		if a.get(i, -1) == -1:
			a[i] = 1
		else:
			a[i] += 1
	maxv = 0
	maxi = 0
	for i in sorted(a.keys()):
		if a[i] >= maxv:
			maxv = a[i]
			maxi = i
	print(max(k * maxv + (maxi + 1) % k + (((maxi + 1) % k == 0) - 1) * k, 0))


import sys
input = sys.stdin.buffer.readline
from collections import Counter
for _ in range(int(input())):
	(n, k) = [int(c) for c in input().split()]
	arr = [int(c) for c in input().split()]
	res = [(k - i % k) % k for i in arr]
	dic = dict(Counter(res))
	ans = 0
	for (i, j) in dic.items():
		if i == 0:
			continue
		else:
			ans = max(ans, (j - 1) * k + i)
	print(ans + 1 if ans > 0 else ans)


import sys, math
t = int(sys.stdin.readline())
for _ in range(t):
	(n, k) = map(int, sys.stdin.readline().split())
	l = list(map(int, sys.stdin.readline().split()))
	last = 0
	liste = [0] * n
	total = 0
	for i in range(n):
		liste[i] = (k - l[i] % k) % k
	liste.sort()
	multiple = 0
	for i in range(1, n):
		if liste[i] != 0 and liste[i] == liste[i - 1]:
			multiple += 1
			total += 1
		elif liste[i] != 0 and liste[i] != liste[i - 1]:
			last = max(last, liste[i - 1] + multiple * k)
			multiple = 0
			total += 1
	last = max(last, liste[n - 1] + multiple * k)
	if last != 0:
		last += 1
	print(last)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = {}
	ans = 0
	for i in range(n):
		we = l[i] % k
		no = k - we
		if no not in d:
			d[no] = 1
		elif no != k:
			d[no] += 1
	for i in d:
		we = 0
		if i != k:
			we = i + (d[i] - 1) * k
		ans = max(ans, we)
	if ans != 0:
		ans += 1
	print(ans)


from sys import stdin
from math import log
T = int(stdin.readline().strip())
for caso in range(T):
	(n, k) = map(int, stdin.readline().strip().split())
	s = list(map(int, stdin.readline().strip().split()))
	aux = []
	for i in range(n):
		if (k - s[i] % k) % k != 0:
			aux.append((k - s[i] % k) % k)
	aux.sort()
	d = dict()
	for i in aux:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	aux1 = set(aux.copy())
	aux = []
	for i in aux1:
		for j in range(d[i]):
			aux.append(i + k * j)
	aux.sort()
	x = 0
	i = 0
	ans = 0
	while i < len(aux):
		if aux[i] >= x:
			ans += aux[i] - x + 1
			x = aux[i] + 1
		else:
			aux.append(aux[i] + k)
		i += 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	rem = dict()
	for i in range(n):
		if arr[i] % k != 0:
			if arr[i] % k not in rem:
				rem[arr[i] % k] = 1
			else:
				rem[arr[i] % k] += 1
	m = 0
	for x in rem:
		t = k - x + k * (rem[x] - 1) + 1
		if t > m:
			m = t
	print(m)


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))

def solve():
	(n, k) = rl()
	A = rl()
	types = dd(int)
	for a in A:
		if a % k == 0:
			continue
		types[(k - a) % k] += 1
	M = 0
	for (rem, count) in types.items():
		M = max(M, (count - 1) * k + rem)
	if M == 0:
		print(M)
	else:
		print(M + 1)
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict as dd

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		nums = list(map(int, input().split()))
		freq = dd(int)
		(maxkey, maxval) = (-1, 0)
		for i in nums:
			t = i % k
			if t != 0:
				freq[k - t] += 1
				if freq[k - t] > maxval:
					maxval = freq[k - t]
		maxkey = 0
		for key in freq:
			if freq[key] == maxval and key > maxkey:
				maxkey = key
		if len(freq) == 0:
			print(0)
			continue
		nummoves = (maxval - 1) * k + (maxkey + 1)
		print(nummoves)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	dp = {}
	for x in a:
		if x % k:
			t = k - x % k
			dp[t] = dp.get(t, 0) + 1
	dp[0] = 0
	cycles = max(dp.values())
	ind = 0
	if cycles == 0:
		print(0)
	else:
		res = k * (cycles - 1)
		for x in dp:
			if dp[x] == cycles:
				ind = max(ind, x)
		res += ind + 1
		print(res)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	arc = []
	for i in range(n):
		if ar[i] % k != 0:
			arc.append(k - ar[i] % k)
	arc.sort()
	d = {}
	for i in arc:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	lis = []
	ans = 0
	for (key, value) in d.items():
		ans = max(ans, key + 1 + (value - 1) * k)
	print(ans)


for _ in range(0, int(input())):
	(n, k) = map(int, input().strip().split())
	l = list(map(int, input().strip().split()))
	diff = []
	import math
	for i in l:
		if i < k:
			diff.append(k - i)
		elif i % k != 0:
			diff.append(int(math.ceil(i / k) * k - i))
	diff.sort()
	if diff == []:
		print(0)
		continue
	multiplier = k
	cur = diff[0]
	for i in range(1, len(diff)):
		if diff[i] == cur:
			diff[i] += multiplier
			multiplier += k
		else:
			multiplier = k
			cur = diff[i]
	print(max(diff) + 1)


from collections import Counter
t = int(input())
while t > 0:
	t -= 1
	(n, k) = map(int, input().split())
	nums = list(map(int, input().split()))
	deviation = [(k - i % k) % k for i in nums]
	maps = {}
	for i in deviation:
		if i == 0:
			maps[i] = -1
		elif i not in maps.keys():
			maps[i] = i
		else:
			maps[i] += k
	print(max(maps.values()) + 1)


from math import *
tests = int(input())
for t in range(tests):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		mod = a[i] % k
		a[i] = k - mod if mod > 0 else 0
	a.sort()
	most_frequent_mod = a[n - 1]
	most_times = 1
	times = 1
	prev = a[n - 1]
	for i in range(n - 2, -1, -1):
		if a[i] == prev:
			times += 1
		else:
			times = 1
			prev = a[i]
		if times > most_times and a[i] > 0:
			most_times = times
			most_frequent_mod = a[i]
	res = (most_times - 1) * k + most_frequent_mod + 1 if most_frequent_mod > 0 else 0
	print(res)


from collections import defaultdict
for x1 in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = defaultdict(int)
	count = 0
	for x in l:
		rem = k - x % k
		if x % k != 0:
			if d[rem] == 0:
				d[rem] = rem
			if count < d[rem]:
				count = d[rem]
			d[rem] += k
	if count != 0:
		print(count + 1)
	else:
		print(0)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	modulo = {}
	for i in range(n):
		m = (k - arr[i]) % k
		if m in modulo:
			modulo[m] += 1
		else:
			modulo[m] = 1
	if 0 in modulo:
		n -= modulo[0]
		modulo[0] = 0
	mxm = 0
	key_mxm = 0
	for (key, value) in modulo.items():
		if value > mxm:
			mxm = value
			key_mxm = key
		elif value == mxm:
			if key > key_mxm:
				mxm = value
				key_mxm = key
	if mxm == 0:
		print(0)
	else:
		print(k * (mxm - 1) + key_mxm + 1)


from collections import Counter, defaultdict, deque
import sys
input = sys.stdin.readline

def primes(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return factors

def solve():
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	for i in range(n):
		a[i] = (k - a[i] % k) % k
	c = Counter(a)
	ans = 0
	for (key, val) in c.items():
		if key != 0:
			ans = max(ans, k * (val - 1) + key + 1)
	print(ans)
tt = int(input())
for test in range(tt):
	solve()


import collections

class Solution:

	def solve(self, nums, k):
		remainder_dict = collections.defaultdict(int)
		for num in nums:
			if num % k > 0:
				remainder_dict[k - num % k] += 1
		if len(remainder_dict) == 0:
			return 0
		(max_v, max_k) = max([[v, k] for (k, v) in remainder_dict.items()])
		return (max_v - 1) * k + max_k + 1
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	nums = list(map(int, input().split()))
	ans = Solution().solve(nums, k)
	print(ans)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	ll = []
	for i in range(a):
		if not l[i] % b == 0:
			ll.append(l[i] % b)
	ll.sort()
	if len(ll) == 0:
		print(0)
	else:
		d = ll[0]
		ma = 1
		mi = 1
		for i in range(1, len(ll)):
			if ll[i] == ll[i - 1]:
				ma += 1
				if ma > mi:
					d = ll[i]
					mi = ma
			else:
				ma = 1
		print((mi - 1) * b + (b - d) + 1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far
from math import *
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	num = list(map(int, input().split()))
	check = dict()
	ans = -1
	for i in num:
		req = k - i % k
		if req != k:
			check.setdefault(req, 0)
			check[req] += 1
	for (f, v) in check.items():
		ans = max(ans, f + (v - 1) * k)
	print(ans + 1)


test = int(input())
from collections import defaultdict
for i in range(test):
	(n, k) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	div = defaultdict(int)
	for i in range(n):
		div[arr[i] % k] += 1
	res = 0
	if div[0] == n:
		print(0)
	else:
		for i in div.items():
			if i[0] != 0:
				res = max(res, (i[1] - 1) * k + k - i[0])
		print(res + 1)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(_) for _ in input().split()]
	d = {}
	for i in a:
		num = (k - i % k) % k
		if num == 0:
			continue
		if num in d:
			d[num] += 1
		else:
			d.setdefault(num, 1)
	(max_key, max_value) = (0, 0)
	for i in d.items():
		if i[1] == max_value:
			if max_key < i[0]:
				max_key = i[0]
		elif i[1] > max_value:
			max_key = i[0]
			max_value = i[1]
	if max_key == 0:
		print(0)
	else:
		print(max_key + k * (max_value - 1) + 1)


from sys import stdin
import collections
t = int(stdin.readline().strip())
for i in range(t):
	(n, k) = list(map(int, stdin.readline().strip().split(' ')))
	A = list(map(int, stdin.readline().strip().split(' ')))
	X = collections.defaultdict(int)
	for a in A:
		if a % k == 0:
			continue
		X[(k - a) % k] += 1
	ans = 0
	for i in X:
		ans = max(ans, k * (X[i] - 1) + i + 1)
	print(ans)


t = int(input())
from collections import defaultdict
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().strip().split()))[:n]
	store = defaultdict(int)
	rem = 0
	for num in arr:
		if num % k == 0:
			continue
		else:
			store[k - num % k] += 1
	if len(store) == 0:
		print(0)
		continue
	store = sorted(store.items(), key=lambda kv: (kv[1], kv[0]))
	(a, b) = store[-1]
	ans = (b - 1) * k + a
	print(ans + 1)


from collections import defaultdict, Counter
from math import ceil, floor, log2
alph = 'abcdefghijklmnopqrstuvwxyz'
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	total = 0
	a = [x for x in a if x % k]
	if not a:
		print(0)
		continue
	counts = defaultdict(int)
	for x in a:
		counts[k - x % k] += 1
	out = 0
	for (x, v) in counts.items():
		out = max(out, x + 1 + (v - 1) * k)
	print(out)


def zeroRemainder(a, n, k):
	hash_map = {}
	for i in range(n):
		if a[i] % k in hash_map:
			hash_map[a[i] % k] += 1
		else:
			hash_map[a[i] % k] = 1
	cnt = 0
	if 0 in hash_map:
		del hash_map[0]
	if not hash_map:
		return 0
	for i in hash_map:
		cnt = max(cnt, hash_map[i] * k - i)
	return cnt + 1 if cnt != 0 else 0
for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	print(zeroRemainder(a, n, k))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	lst1 = []
	dic = {}
	for j in lst:
		rem = j % k
		if rem != 0:
			dic[k - j % k] = 0
	for j in lst:
		rem = j % k
		if rem != 0:
			dic[k - j % k] += 1
	for j in dic.keys():
		ele = j + k * (dic[j] - 1)
		lst1.append(ele)
	if lst1 == []:
		print(0)
	else:
		print(max(lst1) + 1)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = [k - int(x) % k for x in input().split()]
	freq = {}
	for x in a:
		if x < k:
			freq[x] = freq.get(x, 0) + 1
	if len(freq):
		most_freq = max(freq.values())
		last_guy = max([a for (a, b) in freq.items() if b == most_freq])
		print(k * (most_freq - 1) + last_guy + 1)
	else:
		print(0)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	for x in a:
		r = x % k
		if r != 0:
			d[k - r] = d.get(k - r, 0) + 1
	rems = []
	ans = 0
	for x in d:
		o = d[x]
		t = (o - 1) * k + x
		ans = max(ans, t + 1)
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	arr = []
	for j in range(n):
		r = a[j] % k
		if r == 0:
			arr.append(0)
		else:
			arr.append(k - r)
	j = 0
	x = 0
	count = 0
	sme = 0
	arr.sort()
	while j < len(arr) and arr[j] == 0:
		j += 1
	while j < len(arr):
		if j < len(arr) and x < arr[j]:
			x = arr[j]
		while j < len(arr) and x == arr[j]:
			sme += 1
			j += 1
		if sme != 0:
			max_x = x + 1 + (sme - 1) * k
			x += 1
			if max_x > count:
				count = max_x
		sme = 0
	print(count)


cases = int(input())
for _ in range(cases):
	(n, k) = list(map(int, input().strip().split()))
	arr = list(map(int, input().strip().split()))
	d = {}
	for elem in arr:
		rem = elem % k
		if rem != 0:
			rem = k - rem
			if rem in d:
				d[rem] += 1
			else:
				d[rem] = 1
	(maxnum, maxval, max_x) = (0, 0, 0)
	for key in d:
		if d[key] > maxnum or (d[key] == maxnum and key > maxval):
			maxnum = d[key]
			maxval = key
	if d != {}:
		max_x = maxval + (maxnum - 1) * k + 1
	print(max_x)


from collections import defaultdict

def main():
	t = int(input())
	for i in range(t):
		solve()

def solve():
	(n, k) = list(map(int, input().split(' ')))
	arr = list(map(int, input().split(' ')))
	unique = set()
	indexes = defaultdict(int)
	highest = 0
	for i in arr:
		if i % k == 0:
			continue
		val = k - i % k
		if val not in unique:
			if val + 1 > highest:
				highest = val + 1
			unique.add(val)
			indexes[val] = val
		else:
			indexes[val] += k
			val = indexes[val]
			if val + 1 > highest:
				highest = val + 1
			unique.add(val)
	print(highest)
main()


import collections
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().rstrip().split()))
	arr = list(map(int, input().rstrip().split()))
	rem = collections.defaultdict(int)
	for i in arr:
		if i % k != 0:
			rem[k - i % k] += 1
		else:
			rem[0] += 1
	res = 0
	for r in rem:
		if r != 0:
			res = max(res, k * (rem[r] - 1) + r + 1)
	print(res)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	randomarr = []
	for j in range(n):
		hj = l[j] % m
		if hj == 0:
			hj = 0
		else:
			hj = m - hj
		randomarr.append(hj)
	dictio = dict()
	for k in randomarr:
		if k == 0:
			continue
		lk = 0
		if dictio.get(k, 0) == 0:
			dictio[k] = 1
		else:
			dictio[k] += 1
	ans = 0
	for ty in dictio:
		if dictio[ty] > 1:
			ans = max(ty + (dictio[ty] - 1) * m + 1, ans)
		ans = max(ty + 1, ans)
	print(ans)


from sys import stdin, stdout
from sys import maxsize

def solve():
	pass
test = 1
test = int(input())
for t in range(0, test):
	(n, k) = list(map(int, input().split()))
	a = [int(x) for x in input().split()]
	s = {}
	b = [0] * n
	ans = -maxsize
	for i in range(n):
		el = (k - a[i] % k) % k
		if el in s and el != 0:
			s[el] += 1
			el = el + (s[el] - 1) * k
		elif el != 0:
			s[el] = 1
		ans = max(ans, el)
	if ans != 0:
		print(ans + 1)
	else:
		print(0)
	ans = solve()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	d = {}
	ans = 0
	a = list(map(int, input().split()))
	for i in a:
		if i % k != 0:
			c = k - i % k
			if c not in d:
				d[c] = 0
			d[c] += 1
	m = 0
	l = []
	for i in d:
		if d[i] > m:
			m = d[i]
			l = [i]
		elif d[i] == m:
			l.append(i)
	if len(d) != 0:
		ans += (m - 1) * k
		ans += max(l)
		ans += 1
	print(ans)


def all_same(lineup):
	return all([x == 0 for x in lineup])
import sys
for i in range(int(sys.stdin.readline())):
	(size, divisible) = [int(x) for x in sys.stdin.readline().split()]
	lineup = sorted([int(x) % divisible for x in sys.stdin.readline().split()])
	d = {}
	for i in range(size):
		if lineup[i] in d:
			d[lineup[i]] += 1
		else:
			d[lineup[i]] = 1
	highest = -1
	if all_same(lineup):
		print('0')
		continue
	for i in d:
		if i == 0:
			d[i] = 0
		if highest < d[i]:
			highest = d[i]
			check = i
	print(divisible * (highest - 1) + divisible - check + 1)


from collections import defaultdict
test = int(input())
while test != 0:
	(n, k) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	h = defaultdict(int)
	zero = []
	for i in arr:
		zero.append(i % k)
		x = (k - i) % k
		if x:
			if h[x] == 0:
				h[x] = x + 1
			else:
				h[x] += k
	if max(zero) == 0:
		print(0)
	else:
		print(max(h.values()))
	test -= 1


from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def solve(n, k, a):
	increase_needed = [0] * n
	for (i, item) in enumerate(a):
		increase_needed[i] = item % k
	buckets = {}
	for item in increase_needed:
		if item == 0:
			continue
		if item not in buckets:
			buckets[item] = 0
		buckets[item] += 1
	if len(buckets) == 0:
		return 0
	to_find = -1
	to_find_key = -1
	for key in buckets:
		if buckets[key] == to_find and key < to_find_key or buckets[key] > to_find:
			to_find = buckets[key]
			to_find_key = key
	how_many_times_full = to_find - 1
	result = k * how_many_times_full
	result += k - to_find_key + 1
	return result
for i in tests():
	(n, k) = arr_in()
	a = arr_in()
	out(solve(n, k, a))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = [int(x) for x in input().split()]
	ar = []
	f = 0
	for i in l:
		if i % k != 0:
			f = 1
			ar.append(k - i % k)
	if f == 0:
		print(0)
		continue
	d = {}
	for i in ar:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	m = 0
	for i in sorted(d):
		if d[i] >= m:
			m = d[i]
			ans = i
	print(k * (m - 1) + ans + 1)


from heapq import *
from collections import *
import os
import sys
from io import BytesIO, IOBase
import math
import bisect
ins = lambda : [int(x) for x in input()]
inp = lambda : int(input())
inps = lambda : [int(x) for x in input().split()]

def main():
	t = inp()
	for i in range(t):
		(n, k) = inps()
		a = inps()
		rem = []
		for nm in a:
			if nm % k != 0:
				rem.append(k - nm % k)
		dc = Counter(rem)
		ans = 0
		cur = 0
		if not dc:
			print(0)
			continue
		for (ky, v) in dc.items():
			ans = max(ans, ky + (v - 1) * k)
		print(ans + 1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from collections import Counter
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = [int(i) % k for i in input().split()]
	c = Counter(l)
	now = 0
	ma = float('INF')
	for (i, j) in c.items():
		if i == 0:
			continue
		if now < j:
			now = j
			ma = i
		elif now == j:
			if ma > i:
				now = j
				ma = i
	if ma == float('INF'):
		print(0)
	else:
		print(k * (now - 1) + (k - ma) + 1)


from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))

	def func(n, k):
		if n % k != 0:
			return k - n % k
		else:
			return 0
	nl = []
	for i in arr:
		if func(i, k) != 0:
			nl.append(func(i, k))
	if len(nl) > 0:
		q = Counter(nl).most_common()
		depth = q[0][1]
		maxi = q[0][0]
		for i in range(len(q) - 1):
			if q[i][1] == q[i + 1][1]:
				maxi = max(maxi, q[i + 1][0])
			else:
				break
		ans = (depth - 1) * k + maxi + 1
		print(ans)
	else:
		print(0)


from sys import *
for _ in range(int(stdin.readline())):
	(n, k) = [int(x) for x in stdin.readline().split()]
	v = [int(x) for x in stdin.readline().split()]
	d = dict()
	pasi = 0
	lst = 0
	for i in v:
		i = k - i % k
		if i == 0 or i == k:
			continue
		if i not in d.keys():
			d[i] = 1
		else:
			d[i] += 1
		if d[i] > pasi:
			pasi = d[i]
			lst = i
		elif d[i] == pasi:
			lst = max(lst, i)
	stdout.write(str(max(0, k * (pasi - 1) + lst + 1)) + '\n')


for z in range(int(input())):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	a = {}
	ans = 0
	for i in arr:
		g = i % k
		if g != 0:
			if k - g not in a:
				a[k - g] = 0
			a[k - g] += 1
	if len(a) == 0:
		print(0)
	else:
		(con, val) = (0, 0)
		for i in a:
			if a[i] > con:
				con = a[i]
				val = i
			elif a[i] == con and i > val:
				val = i
		print((con - 1) * k + val + 1)


from collections import defaultdict
t = int(input())
for i in range(t):
	d = defaultdict(int)
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	p = 0
	for x in l:
		d[k - x % k] += 1
		if x % k != 0:
			if k * (d[k - x % k] - 1) + (k - x % k) > p:
				p = k * (d[k - x % k] - 1) + (k - x % k)
	if p == 0:
		print(0)
	else:
		print(p + 1)


for _ in range(int(input())):
	(n, k) = [int(p) for p in input().split()]
	a = [int(p) for p in input().split()]
	div = {}
	maxx = 0
	flag = False
	for el in a:
		if el % k > 0:
			flag = True
			if k - el % k not in div:
				div[k - el % k] = 0
			div[k - el % k] += 1
			temp = (div[k - el % k] - 1) * k + (k - el % k)
			maxx = temp if temp > maxx else maxx
	if flag is False:
		print(0)
	else:
		print(maxx + 1)


t = int(input())
from collections import Counter
for _ in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	A = [a % k for a in A]
	C = Counter(A)
	ans = 0
	for (r, v) in C.items():
		r = k - r
		if r == k:
			continue
		q = v - 1
		x = q * k + r
		ans = max(x + 1, ans)
	print(ans)


t = int(input())
rem = {}
for _ in range(t):
	(n, k) = map(int, input().split())
	rem.clear()
	for num in [int(num) for num in input().split()]:
		if num % k not in rem:
			rem[num % k] = 1
		else:
			rem[num % k] += 1
	mx = 0
	for p in rem.items():
		if p[0]:
			cnt = k * p[1] - p[0]
			mx = max(mx, cnt)
	print(mx + 1 if mx else mx)


t = int(input())
for j in range(t):
	(n, k) = map(int, input().split())
	aa = [int(a) for a in input().split()]
	fin = []
	for i in aa:
		fin.append(k - i % k)
	x = 0
	d = {}
	for i in fin:
		if i == k:
			continue
		elif i in d:
			d[i] += 1
		else:
			d[i] = 1
	for j in list(d.keys()):
		x = max(x, k * (d[j] - 1) + j)
	if x:
		print(x + 1)
	else:
		print(x)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	A = list(map(lambda x: k - int(x) % k if int(x) % k else 0, input().split()))
	cnt = 0
	d = {}
	for a in A:
		if a == 0:
			cnt += 1
			continue
		if a not in d:
			d[a] = 1
		else:
			d[a] += 1
	if not d:
		print(0)
		continue
	maxim = max(d.values())
	keys = [i for i in d.keys() if d[i] == maxim]
	key = max(keys)
	ans = k * (maxim - 1) + key + 1
	print(ans)


from collections import defaultdict
rr = lambda : input()
rri = lambda : int(input())
rrm = lambda : list(map(int, input().split()))
INF = float('inf')

def solve(N, K, A):
	diffs = defaultdict(int)
	for v in A:
		diffs[v % K] += 1
	ops = 0
	for remainder in diffs:
		if remainder == 0:
			continue
		ops = max(ops, K - remainder + K * (diffs[remainder] - 1) + 1)
	return ops
t = rri()
for _ in range(t):
	(n, k) = rrm()
	A = rrm()
	print(solve(n, k, A))


from collections import defaultdict, Counter

def tc():
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	ok = True
	bad = []
	for x in a:
		if x % k:
			ok = False
			bad.append(x)
	if ok:
		return 0
	diffs = defaultdict(int)
	for x in bad:
		diffs[k - x % k] += 1
	full = max(diffs.values())
	part = max((rem for (rem, cnt) in diffs.items() if cnt == full))
	ans = k * (full - 1) + part + 1
	return ans
T = int(input())
for _ in range(T):
	ans = tc()
	print(ans)


from sys import stdin, stdout
from collections import Counter
for _ in range(int(stdin.readline())):
	(n, k) = map(int, stdin.readline().split())
	a = list(map(lambda x: int(x) % k, stdin.readline().split()))
	d = Counter(a)
	m = 0
	for (rem, freq) in d.items():
		if rem == 0:
			continue
		m = max(m, k * freq - rem)
	print(0 if m == 0 else m + 1)


from sys import stdin, stdout
import sys
from math import *
for __ in range(int(input())):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	d = {}
	for i in range(n):
		if ar[i] % k != 0:
			if d.get(k - ar[i] % k) == None:
				d[k - ar[i] % k] = 0
			d[k - ar[i] % k] += 1
	ans = 0
	for i in d:
		ans = max(i + (d[i] - 1) * k + 1, ans)
	print(ans)


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	dic = {}
	mx = 0
	for j in arr:
		if j % k == 0:
			continue
		x = k - j % k
		if x in dic:
			dic[x] += 1
		else:
			dic[x] = 1
		mx = max(mx, dic[x])
	if mx == 0:
		print(0)
		continue
	ind = 0
	for j in dic:
		if dic[j] == mx and ind < j:
			ans = k * (mx - 1) + j + 1
			ind = j
	print(ans)


t = int(input())
while t:
	m = f = 0
	(n, k) = map(int, input().split(' '))
	l = list(map(int, input().split(' ')))
	for i in range(n):
		if l[i] % k == 0:
			l[i] = 0
		else:
			l[i] = k - l[i] % k
	l.sort()
	for i in range(n):
		if i > 0 and l[i] == l[i - 1] and (l[i] > 0):
			g += 1
		else:
			g = 1
		if g > m or (g == m and l[i] > f):
			m = g
			f = l[i]
	if f == 0:
		print(0)
	else:
		print((m - 1) * k + f + 1)
	t = t - 1


from collections import OrderedDict, defaultdict
t = int(input())
while t > 0:
	t -= 1
	map__ = OrderedDict()
	map__ = defaultdict(lambda : 0, map__)
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	zero = 0
	for i in l:
		if i % k == 0:
			zero += 1
		else:
			map__[k - i % k] += 1
	max__ = 0
	if zero == n:
		print('0')
	else:
		for key in map__:
			ans = key
			if map__[key] - 1 >= 1 and key != 0:
				ans += (map__[key] - 1) * k
			max__ = max(ans, max__)
		print(max__ + 1)


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


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(lambda x: str((k - int(x)) % k), input().split()))
	dic = {}
	for ae in a:
		if ae != '0':
			if ae in dic:
				dic[ae][0] += 1
			else:
				dic[ae] = [0, int(ae)]
	maxi = 0
	for de in dic:
		maxi = max(dic[de][0] * k + dic[de][1], maxi)
	if maxi == 0:
		print(0)
	else:
		print(maxi + 1)


t = int(input())
for _ in range(t):
	di = {}
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	r = [0 if i % k == 0 else k - i % k for i in l]
	for i in r:
		if i > 0:
			if i in di:
				di[i] += 1
			else:
				di[i] = 1
	c = 0
	v = 0
	for (x, y) in di.items():
		if y > c:
			c = y
			v = x
		elif y == c:
			if v < x:
				v = x
	ans = max(0, v + (c - 1) * k + 1)
	print(ans)


t = int(input())
while t > 0:
	(n, k) = map(int, input().split(' '))
	arri = list(map(int, input().split(' ')))
	x = 0
	for i in range(0, n):
		if arri[i] % k != 0:
			arri[i] = k - arri[i] % k
		else:
			arri[i] = 0
	arri.sort()
	j = 0
	m = 1
	c = 1
	arr = []
	for l in range(0, n):
		if arri[l] > 0:
			arr.append(arri[l])
	if len(arr) == 0:
		print(0)
	else:
		while m < len(arr):
			if arr[m] == arr[j]:
				arr[m] = arr[m] + c * k
				m += 1
				c += 1
			else:
				j = m
				m += 1
				c = 1
		arr.sort()
		print(arr[-1] + 1)
	t = t - 1


t = int(input())
for i in range(t):
	max_value = 0
	zero_ans = True
	(n, k) = map(int, input().split(' '))
	nums = list(map(int, input().split(' ')))
	a = dict()
	for x in nums:
		if x % k != 0:
			x = k - x % k
			if not x in a.keys():
				a[x] = x
			else:
				a[x] += k
				x = a[x]
			max_value = max(max_value, x)
			zero_ans = False
	if zero_ans:
		print(0)
	else:
		print(max_value + 1)


test_case = int(input())
for _ in range(test_case):
	(size, div) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = {arr[i] % div: 0 for i in range(size)}
	for i in arr:
		if i % div:
			s[i % div] += 1
	x = 0
	for i in s.keys():
		x = max(x, s[i] * div - i)
	if x == 0:
		print(0)
	else:
		print(x + 1)


T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = a[i] % k
	a.sort()
	if sum(a) == 0:
		print('0')
	else:
		maximum = 0
		number = -1
		if a[0] == 0:
			temp = 0
		else:
			temp = 1
		for i in range(1, n):
			if a[i] == a[i - 1] and a[i] != 0:
				temp += 1
			elif a[i] != a[i - 1]:
				if maximum < temp:
					maximum = temp
					number = a[i - 1]
				temp = 1
		if maximum < temp:
			maximum = temp
			number = a[n - 1]
		print(k * maximum - number + 1)


from __future__ import division, print_function
import os, sys
import math
import collections
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r))

def binary_search(arr, low, high, x):
	if high >= low:
		mid = (high + low) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binary_search(arr, low, mid - 1, x)
		else:
			return binary_search(arr, mid + 1, high, x)
	else:
		return -1

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def padded_bin_with_complement(x):
	if x < 0:
		return bin(2 ** 16 - abs(x))[2:].zfill(16)
	else:
		return bin(x)[2:].zfill(16)

def binaryToDecimal(binary):
	binary1 = binary
	(decimal, i, n) = (0, 0, 0)
	while binary != 0:
		dec = binary % 10
		decimal = decimal + dec * pow(2, i)
		binary = binary // 10
		i += 1
	print(decimal)

def CountFrequency(arr):
	return collections.Counter(arr)

def pos(a):
	b = [0] * len(a)
	c = sorted(a)
	for i in range(len(a)):
		for j in range(len(a)):
			if c[j] == a[i]:
				b[i] = j
				break
	return b

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def commonn(a, b, n):
	c = []
	for i in range(n):
		if a[i] == b[i]:
			c.append('-1')
		else:
			c.append(b[i])
	return c

def primeFactors(n):
	j = []
	while n % 2 == 0:
		j.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			j.append(int(n))
			n = n / i
	if n > 2:
		j.append(int(n))
	return j

def main():
	for _ in range(ii()):
		(n, k) = mi()
		a = li()
		b = [0] * n
		for i in range(n):
			b[i] = k - a[i] % k
			if b[i] == k:
				b[i] = 0
		b.sort()
		x = 0
		ans = 0
		c = CountFrequency(b)
		final = []
		g = set(b)
		g = list(g)
		for i in range(len(g)):
			for j in range(c[g[i]]):
				if g[i] == 0:
					final.append(0)
					break
				final.append(g[i] + j * k)
		b.sort()
		final.sort()
		for i in range(len(final)):
			if final[i] > x:
				h = x
				x += final[i] - x
				ans += final[i] - h
			if final[i] == x and x > 0:
				x += 1
				ans += 1
				final[i] = 0
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from collections import defaultdict
t = int(input())
while t:
	(n, k) = list(map(int, input().split()))
	d = defaultdict(list)
	a = list(map(int, input().split()))
	m = -1
	for i in a:
		if i % k != 0:
			x = k - i % k
			if x not in d:
				d[x].append(x)
				if x > m:
					m = x
			else:
				temp = d[x][-1] + k
				d[x].append(temp)
				if temp > m:
					m = temp
	print(m + 1)
	t -= 1


for i in range(int(input())):
	(n, k) = map(int, input().split(' '))
	nums = list(map(int, input().split(' ')))
	zeroRem = 0
	remOcc = {}
	for i in nums:
		rem = i % k
		if rem == 0:
			zeroRem += 1
		else:
			remOcc[k - rem] = remOcc.setdefault(k - rem, 0) + 1
	if zeroRem == n:
		print(0)
		continue
	else:
		maxValue = 0
		z = 0
		for i in remOcc:
			z = i + (remOcc[i] - 1) * k
			maxValue = max(maxValue, z)
		print(maxValue + 1)


import math
import heapq
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	minheap = []
	x = 0
	for i in range(n):
		if arr[i] % k != 0:
			minheap.append(k - arr[i] % k)
	if len(minheap) > 0:
		minheap.sort()
		start = minheap[0]
		end = 0
		value = []
		value.append(start)
		for i in range(1, len(minheap)):
			if minheap[i] == minheap[i - 1]:
				value.append(value[i - 1] + k)
			else:
				start = minheap[i]
				value.append(start)
		print(max(value) + 1)
	else:
		print(0)


from sys import stdin, stdout
from collections import Counter
t = int(stdin.readline().strip())
for _ in range(t):
	(n, k) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	r = Counter()
	for i in range(n):
		r[k - a[i] % k] += 1
	c = 0
	for i in r:
		if i == k:
			continue
		c = max(c, i + k * (r[i] - 1) + 1)
	stdout.write('{}\n'.format(c))


t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	k = int(l[1])
	hashi = dict()
	l = input().split()
	li = [int(i) for i in l]
	maxa = []
	for i in li:
		if i % k:
			z = k - i % k
			if z in hashi:
				hashi[z] += 1
			else:
				hashi[z] = 1
	for i in hashi:
		maxa.append((hashi[i] - 1) * k + i)
	if maxa == []:
		print(0)
		continue
	print(max(maxa) + 1)


def findMin(ele, ans, k):
	left = 0
	right = 10 ** 9
	best = None
	while left <= right:
		mid = (left + right) // 2
		if mid * k + ele not in ans:
			best = mid * k + ele
			right = mid - 1
		else:
			left = mid + 1
	return best
I = lambda : list(map(int, input().split(' ')))
for _ in range(I()[0]):
	(n, k) = I()
	lst = I()
	t = []
	for ele in lst:
		if ele % k != 0:
			t.append((ele, k * (1 + ele // k) - ele))
	t = [ele[1] for ele in sorted(t, key=lambda x: x[1])]
	dct = {}
	for ele in t:
		if ele in dct:
			dct[ele] += 1
		else:
			dct[ele] = 1
	if len(dct) != 0:
		ans = set()
		for ele in dct:
			cur = dct[ele]
			for i in range(dct[ele]):
				ans.add(findMin(ele, ans, k))
		print(max(ans) + 1)
	else:
		print(0)


for _ in range(int(input())):
	(n, k) = [int(_) for _ in input().split()]
	A = [int(_) % k for _ in input().split()]
	D = dict()
	m = 0
	for _ in range(n):
		if A[_] != 0:
			if A[_] in D:
				D[A[_]] += 1
			else:
				D[A[_]] = 1
			m = max(m, D[A[_]])
	if D == dict():
		print(0)
	else:
		for _ in sorted(D):
			if m == D[_]:
				print(k * (m - 1) + k - _ + 1)
				break


tst = int(input())
for ts in range(tst):
	(n, k) = map(int, input().split())
	a = [(k - int(i) % k) % k for i in input().split()]
	b = {i: 0 for i in a}
	for i in a:
		b[i] += 1
	(m, mi) = (1, -1)
	for i in sorted(b.keys()):
		if i != 0 and b[i] >= m:
			(m, mi) = (b[i], i)
	if mi == -1:
		print(0)
	else:
		print(k * (b[mi] - 1) + mi + 1)


import sys
input = lambda : sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline

def I():
	return list(map(int, inp().split()))
from collections import Counter
for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) % k for i in input().split()]
	a.sort(reverse=True)
	while a and a[-1] == 0:
		a.pop()
	ans = 0
	for i in range(len(a)):
		a[i] = k - a[i]
	if len(a) != 0:
		d = Counter(a)
		val = [0, 0]
		for i in d:
			if val[1] < d[i]:
				val[1] = d[i]
				val[0] = i
			elif val[1] == d[i] and i > val[0]:
				val[0] = i
		print((val[1] - 1) * k + val[0] + 1)
	else:
		print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	m = {}
	for i in range(n):
		if A[i] % k == 0:
			continue
		temp = A[i] % k
		temp = k - temp
		if m.get(temp) == None:
			m[temp] = 1
		else:
			tmp = m.get(temp)
			m[temp] = tmp + 1
	maxV = 0
	idx = 0
	for i in m:
		if maxV <= m[i]:
			if maxV == m[i]:
				if idx < i:
					idx = i
			else:
				idx = i
				maxV = m[i]
	if maxV == 0:
		res = 0
	else:
		res = (maxV - 1) * k + idx + 1
	print(res)


from collections import defaultdict
t = int(input())
while t:
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	myMap = defaultdict(int)
	for val in arr:
		modVal = val % k
		if modVal == 0:
			continue
		myMap[modVal] += 1
	cnt = 0
	for val in myMap:
		cnt = max(cnt, myMap[val] * k - val)
	print(cnt + 1 if cnt != 0 else 0)
	t -= 1


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	lst = []
	for i in l:
		if i < k:
			lst.append(k - i)
		elif i % k:
			lst.append(int(math.ceil(i / k) * k - i))
	lst.sort()
	if not len(lst):
		print(0)
		continue
	m = k
	c = lst[0]
	for i in range(1, len(lst)):
		if lst[i] == c:
			lst[i] += m
			m += k
		else:
			m = k
			c = lst[i]
	print(max(lst) + 1)


from collections import Counter
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	c = list(map(lambda x: x % k, a))
	if len(set(c)) == 1 and c[0] == 0:
		print(0)
	else:
		d = Counter(c)
		Q = d.most_common()
		if Q[0][0] == 0:
			q = Q[1][1]
			i = 1
		else:
			q = Q[0][1]
			i = 0
		temp = []
		while i < len(Q) and Q[i][1] == q:
			temp.append(Q[i][0])
			i += 1
		temp.sort()
		if temp[0] == 0:
			ind = temp[1]
		else:
			ind = temp[0]
		count = 1 + k * (q - 1)
		count += k - ind
		print(count)


from collections import Counter
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	mods = Counter([int(x) % k for x in input().split()])
	del mods[0]
	common = mods.most_common()
	if not common:
		print(0)
		continue
	max_count = common[0][1]
	maxes = [x[0] for x in common if x[1] == max_count]
	min_rem = min(maxes)
	print((max_count - 1) * k + k - min_rem + 1)


import heapq
from collections import defaultdict
from sys import stdin
input = stdin.readline
INF = 10 ** 9 + 7
MAX = 10 ** 7 + 7
MOD = 10 ** 9 + 7
for Ti in range(int(input().strip())):
	(n, k) = [int(x) for x in input().strip().split()]
	a = [int(x) for x in input().strip().split()]
	d = defaultdict(int)
	d[0] = float('inf')
	(h1, h2) = ([], [])
	for ai in a:
		if ai % k:
			d[k - ai % k] += 1
	for di in d:
		heapq.heappush(h1, [di, d[di]])
	c = 0
	ans = 0
	while len(h1) > 1:
		while len(h1):
			(ce, cc) = heapq.heappop(h1)
			if c < ce:
				ans += ce - c
			ans += 1
			c = ce + 1
			cc -= 1
			if cc:
				heapq.heappush(h2, [ce + k, cc])
		h1 = h2
		h2 = []
	print(ans)


def remainder_array(n, k, a):
	used = set()
	m = 0
	for x in a:
		diff = k - x % k
		if diff != k:
			while diff in used:
				diff = diff + k
			used.add(diff)
			m = max(m, diff)
	if m == 0:
		return 0
	else:
		return m + 1

def remainder_faster(n, k, a):
	diffs = {}
	m = 0
	for x in a:
		diff = k - x % k
		if diff != k:
			diffs[diff] = diffs.get(diff, 0) + 1
	for (diff, count) in diffs.items():
		m = max(m, diff + k * (count - 1))
	if m == 0:
		return 0
	else:
		return m + 1
t = int(input())
for case in range(t):
	(n, k) = map(int, input().split())
	a = map(int, input().split())
	print(remainder_faster(n, k, a))


t = 1
t = int(input())
from collections import defaultdict
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	ans = 0
	cnt = 0
	vis = defaultdict(lambda : 0)
	for i in arr:
		if i % k != 0:
			req = k - i % k
			req += vis[req] * k
			vis[k - i % k] += 1
			ans = max(req, ans)
			cnt += 1
	print(ans + int(cnt != 0))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	x = 0
	undivCnt = 0
	maxUndiv = 0
	l = []
	d = {}
	res = 0
	for i in range(n):
		if a[i] % k != 0:
			undivCnt += 1
			need = a[i] // k * k + k - a[i]
			if need in d:
				d[need] += 1
			else:
				d[need] = 1
	for (key, val) in d.items():
		if val > 1:
			d[key] = key + k * (val - 1)
		else:
			d[key] = key
		res = max(res, d[key])
	if d:
		print(res + 1)
	else:
		print(0)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def msi():
	return map(str, input().split())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mod = 1000000007
from math import log, log2, sqrt, factorial, cos, tan, sin, radians, ceil, floor
import bisect
from decimal import *
abc = 'abcdefghijklmnopqrstuvwxyz'
pi = 3.141592653589793

def main():
	for _ in range(ii()):
		(n, k) = mi()
		a = li()
		a.sort()
		d = {}
		for i in range(n):
			x = a[i] % k
			if x in d:
				d[x] += 1
			else:
				d[x] = 1
		ans = -1
		for i in d:
			if i == 0:
				continue
			e = k - i
			e += (d[i] - 1) * k
			ans = max(ans, e)
		ans += 1
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
while t:
	m = 0
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	for x in a:
		if x % k not in d:
			d[x % k] = 1
		else:
			d[x % k] += 1
	for x in d:
		if x:
			m = max(m, d[x] * k - x)
	if not m:
		print(m)
	else:
		print(m + 1)
	t -= 1


t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	m = {}
	for (i, elem) in enumerate(input().split()):
		key = (k - int(elem) % k) % k
		if key != 0:
			m[key] = m.get(key, 0) + 1
	max_item = (0, 0)
	for item in m.items():
		normal_item = (item[1], item[0])
		if max_item < normal_item:
			max_item = normal_item
	if m:
		print(max_item[0] * k - (k - max_item[1] - 1))
	else:
		print(max_item[0] * k)


tst = int(input())
for sa in range(tst):
	(nsa, ksa) = map(int, input().split())
	lsa = list(map(int, input().split()))
	hsa = []
	dsa = {}
	h2sa = 0
	zsa = 0
	for jsa in range(nsa):
		csa = lsa[jsa] % ksa
		if csa == 0:
			hsa.append(csa)
			msa = 0
			zsa = zsa + 1
		else:
			hsa.append(ksa - csa)
			msa = ksa - csa
		if msa not in dsa and msa != 0:
			dsa[msa] = 1
		elif msa != 0:
			dsa[msa] = dsa[msa] + 1
	if zsa != nsa:
		h1sa = max(dsa.values())
		for jsa in dsa:
			if dsa[jsa] == h1sa:
				if h2sa < jsa:
					h2sa = jsa
		csa = h1sa * ksa
		csa = csa - (ksa - h2sa) + 1
		print(csa)
	else:
		print(0)


from sys import stdin
from collections import OrderedDict
a = int(stdin.readline().rstrip())
for _ in range(a):
	(n, k) = map(int, stdin.readline().rstrip().split(' '))
	l = list(map(int, stdin.readline().rstrip().split(' ')))
	s = l.copy()
	z = dict()
	for i in range(n):
		x = l[i] % k
		if x:
			t = z.get(x, 0)
			if t:
				z[x] += 1
			else:
				z[x] = 1
	z = OrderedDict(sorted(z.items()))
	if not z:
		print(0)
	else:
		a = max(z, key=z.get)
		sol = k - a + 1 + k * (z[a] - 1)
		print(sol)


from collections import Counter
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	rem = []
	for j in range(n):
		if l[j] % k != 0:
			rem.append(l[j] % k)
	freq = Counter(rem)
	(max_value, max_num) = (0, 0)
	for j in freq:
		if freq[j] > max_value:
			max_value = freq[j]
			max_num = j
		elif freq[j] == max_value and j < max_num:
			max_num = j
	if max_value == max_num == 0:
		print(0)
	else:
		print(k * max_value - (max_num - 1))