You are given an array $a_1, a_2, \ldots, a_n$ consisting of $n$ positive integers and a positive integer $m$.

You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want.

Let's call an array $m$-divisible if for each two adjacent numbers in the array (two numbers on the positions $i$ and $i+1$ are called adjacent for each $i$) their sum is divisible by $m$. An array of one element is $m$-divisible.

Find the smallest number of $m$-divisible arrays that $a_1, a_2, \ldots, a_n$ is possible to divide into.


-----Input-----

The first line contains a single integer $t$ $(1 \le t \le 1000)$  — the number of test cases.

The first line of each test case contains two integers $n$, $m$ $(1 \le n \le 10^5, 1 \le m \le 10^5)$.

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \le a_i \le 10^9)$.

It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $10^5$.


-----Output-----

For each test case print the answer to the problem.


-----Examples-----

Input
4
6 4
2 2 8 6 9 4
10 8
1 1 1 5 2 4 4 8 6 7
1 1
666
2 2
2 4
Output
3
6
1
1


-----Note-----

In the first test case we can divide the elements as follows:

$[4, 8]$. It is a $4$-divisible array because $4+8$ is divisible by $4$.

$[2, 6, 2]$. It is a $4$-divisible array because $2+6$ and $6+2$ are divisible by $4$.

$[9]$. It is a $4$-divisible array because it consists of one element.

Source: codeforces | Difficulty: EASY
Tags: Greedy algorithms

Mathematics

Constructive algorithms


Solutions:
from collections import Counter
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	ali = list(map(int, input().split()))
	q = Counter()
	cnt = 0
	for i in range(n):
		w = ali[i] % m
		q[w] += 1
	if m % 2 == 0:
		e = m // 2
	else:
		e = m // 2 + 1
	for i in range(1, m // 2 + 1):
		a = abs(m - i)
		z = q[a]
		x = q[i]
		if z != 0 and x != 0 and (i != a):
			if z == x:
				cnt += 1
			elif z < x:
				x = x - (z + 1)
				cnt += x
				cnt += 1
			else:
				z = z - (x + 1)
				cnt += 1
				cnt += z
		elif i == a and q[i] > 0:
			if i + i == m:
				cnt += 1
		else:
			cnt += x
			cnt += z
	v = q[0]
	if v > 0:
		cnt += 1
	print(cnt)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	c = {}
	for x in map(int, input().split()):
		x %= m
		c[x] = c.get(x, 0) + 1
	a = 0
	for (k, v) in c.items():
		if k == 0:
			a += 1
		elif k * 2 == m:
			a += 1
		elif m - k not in c:
			a += v
		elif k * 2 < m:
			x = c.get(m - k, 0)
			if abs(v - x) > 1:
				a += abs(v - x) - 1 + 1
			else:
				a += 1
	print(a)


for rpt in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	numbers = [int(x) for x in input().split()]
	remains = [0 for x in range(m)]
	for i in numbers:
		remains[i % m] += 1
	res = 0
	for i in range(m // 2 + 1):
		if remains[i] > 0 or remains[(m - i) % m] > 0:
			smaller = min(remains[i], remains[(m - i) % m])
			bigger = max(remains[i], remains[(m - i) % m])
			if bigger - smaller <= 1:
				res += 1
			else:
				res += bigger - smaller - 1 + 1
	print(res)


def reduce(i, m):
	i %= m
	if i > m // 2:
		i -= m
	return i

def groups(a, b):
	return max(abs(a - b), 1)

def solve(arr, m):
	res = 0
	d = {}
	for i in arr:
		d[abs(i)] = d.get(abs(i), 0) + (1 if i > 0 else -1)
	for i in d:
		if i != 0 and i != m / 2:
			res += max(abs(d[i]), 1)
	res += 0 in d
	res += m % 2 == 0 and m // 2 in d
	return res
t = int(input())
ans = []
for i in range(t):
	(n, m) = map(int, input().split())
	arr = [reduce(int(i), m) for i in input().split()]
	ans.append(solve(arr, m))
for i in ans:
	print(i)


for t in range(int(input())):
	(N, M) = map(int, input().split())
	arr = list(map(int, input().split()))
	mp = [0 for i in range(M)]
	ans = 0
	for i in arr:
		mp[i % M] += 1
	if mp[0] > 0:
		ans += 1
	for j in range(1, M // 2 + 1):
		if mp[j] == 0 or mp[M - j] == 0:
			ans += max(mp[j], mp[M - j])
		elif mp[j] == mp[M - j]:
			ans += 1
		elif mp[j] > mp[M - j]:
			if mp[j] - mp[M - j] <= 1:
				ans += 1
			else:
				mp[j] -= mp[M - j] + 1
				ans += mp[j] + 1
		elif mp[M - j] - mp[j] <= 1:
			ans += 1
		else:
			mp[M - j] -= mp[j] + 1
			ans += mp[M - j] + 1
	print(ans)


def solve():
	testis = int(input())
	for t in range(testis):
		(n, m) = map(int, input().split())
		a = list(map(int, input().split()))
		b = [0] * m
		for j in a:
			b[j % m] += 1
		ans = 0
		if b[0] > 0:
			ans += 1
		for j in range(1, (m + 1) // 2):
			if b[j] or b[m - j]:
				ans += max(1, abs(b[m - j] - b[j]))
		if m % 2 == 0:
			if b[m // 2]:
				ans += 1
		print(ans)
solve()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = [0 for i in range(k)]
	for i in range(n):
		d[l[i] % k] += 1
	ans = 0
	if d[0] > 0:
		ans += 1
	for i in range(1, k // 2 + 1):
		if d[i] == 0 or d[k - i] == 0:
			ans += d[i] + d[k - i]
		elif abs(d[i] - d[k - i]) <= 1:
			ans += 1
		else:
			ans += abs(d[i] - d[k - i])
	print(ans)


from sys import stdin
std = stdin.readline
T = int(std())
while T > 0:
	T -= 1
	(n, m) = map(int, std().split())
	arr = list(map(int, std().split()))
	div = [0 for i in range(m)]
	for a in arr:
		div[a % m] += 1
	ans = 0
	div_two = m // 2
	for i in range(div_two + 1):
		if i == 0:
			if div[i] > 0:
				ans += 1
			continue
		if m % 2 == 0 and i == div_two and (div[i] > 0):
			ans += 1
		else:
			if div[i] == 0 and div[m - i] == 0:
				continue
			if div[i] == div[m - i]:
				ans += 1
			elif div[i] == 0 or div[m - i] == 0:
				ans += abs(div[i] - div[m - i])
			elif div[i] > div[m - i]:
				ans += div[i] - div[m - i] - 1
				ans += 1
			else:
				ans += div[m - i] - div[i] - 1
				ans += 1
	print(ans)


import math
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	rems = [0] * m
	for e in a:
		rems[e % m] += 1
	ans = 1 if rems[0] > 0 else 0
	for i in range(1, m // 2 + 1):
		if rems[i] == 0 and rems[m - i] == 0:
			continue
		(matched, unmatched) = (min(rems[i], rems[m - i]), abs(rems[i] - rems[m - i]))
		if matched > 0:
			ans += 1
			unmatched -= 1
		if unmatched > 0:
			ans += unmatched
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	rem = [0 for i in range(m)]
	count = 0
	for i in range(n):
		rem[l[i] % m] += 1
	count = 0
	count1 = n
	if rem[0]:
		count += 1
		count1 -= rem[0]
	for i in range(1, m // 2 + 1):
		if (m % 2 == 0 and i == m // 2) and rem[m // 2]:
			count += 1
			count1 -= rem[m // 2]
		elif rem[i] == 0 or rem[m - i] == 0:
			continue
		elif rem[i] == rem[m - i]:
			count += 1
			count1 -= rem[i]
			count1 -= rem[m - i]
		else:
			count += 1
			count1 -= 2 * min(rem[i], rem[m - i]) + 1
	print(count + count1)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	num = [0] * m
	for i in range(n):
		num[a[i] % m] += 1
	if num[0] > 0:
		res = 1
	else:
		res = 0
	for i in range(1, m // 2 + 1):
		if abs(num[i] - num[m - i]) <= 1 and (num[i] > 0 or num[m - i] > 0):
			res += 1
		else:
			res += abs(num[i] - num[m - i])
	print(res)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	if m == 1:
		print(1)
	else:
		trash = [0] * m
		for i in arr:
			temp = i % m
			trash[temp] += 1
		c = 0
		for i in range(m // 2 + 1):
			j = (m - i) % m
			if trash[i] + trash[j] > 0:
				bruh = abs(trash[i] - trash[j])
				c += max(bruh, 1)
		print(c)


import sys
from collections import Counter

def solve(arr, k):
	ans = 1 if arr[0] > 0 else 0
	(a, b) = (1, k - 1)
	while a <= b:
		if arr[a] == arr[b] and arr[a] > 0:
			ans += 1
		else:
			ans += abs(arr[a] - arr[b])
		a += 1
		b -= 1
	sys.stdout.write(str(ans) + '\n')
for _ in range(int(input())):
	(n, k) = map(int, sys.stdin.readline().split())
	arr = Counter([int(x) % k for x in sys.stdin.readline().split()])
	solve(arr, k)


from collections import Counter
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [int(i) % m for i in input().split()]
	d = Counter(a)
	res = 0
	for e in set(a):
		if d[e] < 0:
			continue
		cur = (m - e) % m
		v = min(d[cur], d[e]) + (d[cur] != d[e])
		res += max(d[cur], d[e]) - v + 1
		d[cur] = -1
	print(res)


def main():
	t = int(input())
	for _ in range(t):
		(n, m) = list(map(int, input().split()))
		a = list(map(int, input().split()))
		r = [0] * m
		for i in range(n):
			r[a[i] if a[i] < m else a[i] % m] += 1
		arr = 0
		if r[0] != 0:
			arr += 1
		p = m // 2 + 1
		if m % 2 == 1:
			for i in range(1, p):
				if r[i] == 0 and r[m - i] == 0:
					pass
				elif r[i] == r[m - i]:
					arr += 1
				elif r[i] >= r[m - i]:
					arr += r[i] - r[m - i]
				else:
					arr += r[m - i] - r[i]
		else:
			for i in range(1, p - 1):
				if r[i] == 0 and r[m - i] == 0:
					pass
				elif r[i] == r[m - i]:
					arr += 1
				elif r[i] >= r[m - i]:
					arr += r[i] - r[m - i]
				else:
					arr += r[m - i] - r[i]
			if r[p - 1] != 0:
				arr += 1
		print(arr)
main()


from collections import Counter
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	l1 = []
	for i in range(n):
		l1.append(l[i] % m)
	c = Counter(l1)
	ans = 0
	for i in range(m // 2 + 1):
		if i == 0:
			if i in c:
				ans += 1
		else:
			diff = abs(i - m)
			temp = i
			if diff in c and temp in c:
				if c[diff] < c[temp]:
					c_diff = c[diff]
					c[temp] -= c_diff + 1
					c[diff] = 0
					ans += 1
				elif c[diff] > c[temp]:
					c_temp = c[temp]
					c[diff] -= c_temp + 1
					c[temp] = 0
					ans += 1
				else:
					c[diff] = 0
					c[temp] = 0
					ans += 1
				if c[diff] > 0:
					ans += c[diff]
					c[diff] = 0
				if c[temp] > 0:
					ans += c[temp]
					c[temp] = 0
			elif diff in c:
				ans += c[diff]
				c[diff] = 0
			elif temp in c:
				ans += c[temp]
				c[temp] = 0
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(lambda x: int(x) % m, input().split()))
	d = dict()
	for i in arr:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	ans = 0
	if 0 in d:
		ans += 1
	for i in range(1, int(m / 2) + 1):
		if i == m - i and i in d:
			ans += 1
			continue
		if i in d and m - i in d:
			if d[i] == d[m - i]:
				ans += 1
				continue
			ans += max(d[i], d[m - i]) - min(d[i], d[m - i])
		elif i in d:
			ans += d[i]
		elif m - i in d:
			ans += d[m - i]
	print(ans)


T = int(input())

def solve(arr, N, M):
	rems = [0] * M
	for a in arr:
		rems[a % M] += 1
	res = 0
	i = 0
	while i * 2 <= M:
		x = rems[i]
		y = rems[M - i] if i != 0 else rems[0]
		i += 1
		if x < y:
			(x, y) = (y, x)
		if x == 0:
			continue
		if y >= x - 1:
			res += 1
			continue
		res += x - y
	return res
for _ in range(T):
	(N, M) = map(int, input().split())
	arr = map(int, input().split())
	res = solve(arr, N, M)
	print(res)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	store = [0 for i in range(m + 1)]
	a = list(map(int, input().split()))
	for i in range(n):
		store[a[i] % m] += 1
	count = 0
	for i in range(m // 2 + 1):
		if i == 0:
			if store[i] > 0:
				count += 1
		elif i == m - i and store[i] > 0:
			count += 1
		elif store[i] > 0 or store[m - i] > 0:
			count += max(1, max(store[i], store[m - i]) - min(store[i], store[m - i]))
	print(count)


def main():
	for _ in range(int(input())):
		(n, m) = tuple(map(int, input().split()))
		a = list(map(int, input().split()))
		dp = [0] * m
		res = 0
		for i in a:
			dp[i % m] += 1
		if dp[0] > 0:
			res += 1
		for i in range(1, (m + 1) // 2):
			if dp[i] or dp[m - i]:
				res += max(1, abs(dp[i] - dp[m - i]))
		if m % 2 == 0 and dp[m // 2]:
			res += 1
		print(res)
main()


import sys
input = sys.stdin.readline

def main():
	(n, m) = map(int, input().split())
	alst = list(map(int, input().split()))
	cnt = [0] * m
	for a in alst:
		cnt[a % m] += 1
	ans = 0
	for i in range(1, (m + 1) // 2):
		min_ = min(cnt[i], cnt[m - i])
		max_ = max(cnt[i], cnt[m - i])
		if min_ == max_ == 0:
			continue
		else:
			ans += max(1, max_ - min_)
	if cnt[0] > 0:
		ans += 1
	if m % 2 == 0 and cnt[m // 2] > 0:
		ans += 1
	print(ans)
for _ in range(int(input())):
	main()


import os, sys
from io import BytesIO, IOBase
from collections import Counter

def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		a = Counter(map(lambda xx: int(xx) % m, input().split()))
		ans = 0
		if a[0]:
			ans += 1
		for i in range(1, m):
			if i > m - i:
				break
			if i == m - i:
				if a[i]:
					ans += 1
				break
			(x, y) = (min(a[i], a[m - i]), max(a[i], a[m - i]))
			if x:
				ans += 1
				ans += max(0, y - x - 1)
			else:
				ans += y - x
		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()


from sys import stdin
input = lambda : stdin.readline().strip()
lin = lambda : list(map(int, input().split()))
iin = lambda : int(input())
main = lambda : map(int, input().split())
from math import ceil, sqrt, factorial, log
from collections import deque
from bisect import bisect_left
mod = 998244353
mod = 1000000007

def gcd(a, b):
	(a, b) = (max(a, b), min(a, b))
	while a % b != 0:
		(a, b) = (b, a % b)
	return b

def moduloinverse(a):
	return pow(a, mod - 2, mod)

def solve(we):
	(n, m) = main()
	l = lin()
	ans = 1
	z = [0 for i in range(m)]
	for i in l:
		z[i % m] += 1
	ans = 0
	if z[0] > 0:
		ans += 1
	for i in range(1, m):
		if 2 * i == m:
			if z[i] > 0:
				ans += 1
		elif m - i >= m / 2:
			mi = min(z[i], z[m - i])
			ma = max(z[i], z[m - i])
			if mi == ma:
				if mi > 0:
					ans += 1
			elif ma - mi == 1:
				ans += 1
			else:
				t = ma - mi - 1
				ans += t + 1
		else:
			break
	print(ans)
qwe = iin()
for _ in range(qwe):
	solve(_ + 1)


T = int(input())
for t in range(T):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	d = [0] * m
	for e in a:
		d[e % m] += 1
	count = d[0] > 0
	for i in range(1, (m + 1) // 2):
		if d[i] != 0 or d[m - i] != 0:
			if d[i] == d[m - i]:
				count += 1
			else:
				count += abs(d[i] - d[m - i])
	if m % 2 == 0:
		count += d[m // 2] > 0
	print(int(count))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	lista = list(map(int, input().split()))
	ans = []
	dicio = {}
	for i in range(len(lista)):
		ans.append(lista[i] % k)
		if lista[i] % k not in dicio:
			dicio[lista[i] % k] = 1
		else:
			dicio[lista[i] % k] += 1
	ans = sorted(ans)
	res = 0
	for i in range(k // 2 + 1):
		if i in dicio:
			if i == 0:
				res += 1
			elif k - i in dicio:
				res += 1
				res += max(abs(dicio[k - i] - dicio[i]) - 1, 0)
			else:
				res += dicio[i]
		elif k - i in dicio:
			res += dicio[k - i]
	print(res)


def processing():
	(n, m) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	deli = [0] * m
	for x in a:
		deli[x % m] += 1
	res = 0
	if deli[0] != 0:
		res += 1
		deli[0] = 0
	if m % 2 == 0:
		for i in range(1, m // 2):
			if deli[i] == 0 and deli[m - i] == 0:
				continue
			if abs(deli[i] - deli[m - i]) <= 1:
				res += 1
			else:
				res += abs(deli[i] - deli[m - i])
			deli[i] = 0
			deli[m - i] = 0
		if deli[m // 2] != 0:
			res += 1
			deli[m // 2] = 0
	else:
		for i in range(1, m // 2 + 1):
			if deli[i] == 0 and deli[m - i] == 0:
				continue
			if abs(deli[i] - deli[m - i]) <= 1:
				res += 1
			else:
				res += abs(deli[i] - deli[m - i])
			deli[i] = 0
			deli[m - i] = 0
	print(res)
t = int(input())
for i in range(t):
	processing()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	t = [0] * m
	for i in range(n):
		t[arr[i] % m] += 1
	count = 0
	i = 1
	j = len(t) - 1
	while i <= j:
		if t[i] == 0 and t[j] == 0:
			i += 1
			j -= 1
			continue
		elif t[i] == 0 or t[j] == 0:
			count += t[i] + t[j]
			i += 1
			j -= 1
			continue
		f = min(t[i], t[j])
		t[i] -= f
		t[j] -= f
		if t[i] >= 1 or t[j] >= 1:
			count += max(t[i], t[j])
		else:
			count += 1
		i += 1
		j -= 1
	if t[0] > 0:
		count += 1
	print(count)


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 prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	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()))
	ivs = [0] * k
	for i in a:
		ivs[i % k] += 1
	ans = 1 if ivs[0] else 0
	if k % 2 == 0:
		ans += 1 if ivs[k // 2] else 0
	for i in range(1, (k + 1) // 2):
		if ivs[i] or ivs[k - i]:
			(x, y) = (min(ivs[i], ivs[k - i]), max(ivs[i], ivs[k - i]))
			if x == 0:
				ans += y
				continue
			ans += 1
			y -= x
			y -= 1
			if y > 0:
				ans += y
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ar = list(map(int, input().split()))
	rem = {}
	for i in ar:
		xx = i % m
		if xx in rem:
			rem[xx] += 1
		else:
			rem[xx] = 1
	ans = 0
	for i in rem:
		if rem[i] != 0:
			if i == m - i or i == 0:
				ans += 1
			else:
				i1 = i
				i2 = m - i
				x1 = rem[i1]
				x2 = rem.get(i2, 0)
				ans += 1
				if x1 > x2:
					x1 -= x2 + 1
					x2 = 0
				elif x1 < x2:
					x2 -= x1 + 1
					x1 = 0
				else:
					x1 = 0
					x2 = 0
				ans += x1 + x2
				rem[i1] = 0
				if i2 in rem:
					rem[i2] = 0
	print(ans)


from math import *
from collections import defaultdict as dt
from sys import stdin
inp = lambda : stdin.readline().strip()
I = lambda : int(inp())
M = lambda : map(int, stdin.readline().split())
L = lambda : list(map(int, stdin.readline().split()))
mod = 1000000009
inf = 100000000000000000000
ss = 'abcdefghijklmnopqrstuvwxyz'

def solve():
	(n, m) = M()
	a = L()
	c = 0
	d = dt(lambda : 0)
	for i in a:
		d[i % m] += 1
		d[m - i % m]
	for i in d:
		if i == m - i and d[i] != 0:
			c = c + 1
		elif (i == 0 or i == m) and d[i] != 0:
			c = c + 1
		elif d[i] == d[m - i] != 0:
			c = c + 1
		else:
			c = c + abs(d[i] - d[m - i])
		d[i] = 0
		d[m - i] = 0
	print(c)
tt = 1
tt = I()
for _ in range(tt):
	solve()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = [0] * k
	c = 0
	for i in a:
		b[i % k] += 1
	for i in range(k // 2 + 1):
		if i == 0:
			if b[i]:
				c += 1
			else:
				continue
		else:
			x = min(b[i], b[k - i % k])
			y = max(b[i], b[k - i % k])
			if x == y + 1 or y == x + 1:
				c += 1
			elif x == 0 and y == 0:
				continue
			elif x == 0 or y == 0:
				c += max(x, y)
			elif x == y:
				c += 1
			else:
				c += y - x
	print(c)


import sys
t = int(sys.stdin.readline())
for i in range(t):
	(n, m) = map(int, sys.stdin.readline().split())
	data = list(map(int, sys.stdin.readline().split()))
	num = [0] * m
	for item in data:
		num[item % m] += 1
	ans = 0
	if num[0] != 0:
		ans += 1
		num[0] = 0
	for start in range(1, m // 2 + 1):
		end = m - start
		temp = min(num[start], num[end])
		if temp != 0:
			ans += 1
			if start == end:
				num[start] = 0
				continue
			if num[start] == num[end]:
				num[end] -= temp
				num[start] -= temp
				continue
			if num[start] == temp:
				num[end] -= temp + 1
				num[start] -= temp
			else:
				num[start] -= temp + 1
				num[end] -= temp
	ans += sum(num)
	print(ans)


def solve(A, n, m):
	if m == 1:
		return 1
	freq = [0] * m
	for a in A:
		freq[a % m] += 1
	result = 1 if freq[0] > 0 else 0
	for i in range(1, m // 2):
		if freq[i] == 0 and freq[m - i] == 0:
			continue
		d = abs(freq[i] - freq[m - i])
		result += max(d, 1)
	if m % 2 == 1:
		if not (freq[m // 2] == 0 and freq[m - m // 2] == 0):
			d = abs(freq[m // 2] - freq[m - m // 2])
			result += max(d, 1)
	else:
		result += 1 if freq[m // 2] > 0 else 0
	return result
t = int(input())
for tc in range(t):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	result = solve(A, n, m)
	print(result)


from collections import Counter
t = int(input())
for q in range(0, t):
	(n, m) = map(int, input().split())
	a = [int(x) % m for x in input().split()]
	cnt = Counter(a)
	ans = 0
	for i in set(a):
		if cnt[i] == -1000000000.0:
			continue
		r = (m - i) % m
		ans += max(abs(cnt[r] - cnt[i]), 1)
		cnt[r] = -1000000000.0
	print(ans)


import sys
input = sys.stdin.readline

class Problem:

	def __init__(self):
		pass

	def solve(self):
		t = int(input())
		for _ in range(t):
			(n, m) = map(int, input().split())
			A = list(map(int, input().split()))
			ans = 0
			rem = {}
			for a in A:
				r = a % m
				mr = m - r
				if r not in rem and mr not in rem:
					ans += 1
					rem[r] = 0
				if r in rem:
					rem[r] += 1
				if mr in rem:
					rem[mr] -= 1
			for (k, v) in rem.items():
				if k == 0:
					continue
				extra = abs(v)
				if extra > 1:
					ans += extra - 1
			print(ans)

def main():
	p = Problem()
	p.solve()
main()


from sys import stdin
readline = stdin.readline
sr = lambda : readline()
ir = lambda : int(sr())
lr = lambda : list(map(int, sr().split()))
inf = 10 ** 18
mod = 998244353
test = ir()
for t in range(test):
	(n, m) = lr()
	a = lr()
	dic = {}
	for num in a:
		tmp = num % m
		if tmp in dic:
			dic[tmp] += 1
		else:
			dic[tmp] = 1
	ans = 0
	ret = n
	for num in range(m // 2 + 1):
		if num in dic and dic[num] > 0:
			if num == 0:
				ans += 1
				ret -= dic[num]
			elif m % 2 == 0 and num == m // 2:
				ans += 1
				ret -= dic[num]
			elif m - num in dic:
				ans += 1
				if abs(dic[num] - dic[m - num]) > 0:
					ret -= min(dic[num], dic[m - num]) * 2 + 1
				else:
					ret -= min(dic[num], dic[m - num]) * 2
	ans += ret
	print(ans)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	if n == 1:
		a = list(map(lambda x: int(x) % m, input().split()))
		print(1)
	else:
		a = list(map(lambda x: int(x) % m, input().split()))
		arr = [0 for i in range(m)]
		for items in a:
			arr[items] += 1
		if arr[0] > 0:
			ans = 1
		else:
			ans = 0
		arr = arr[1:]
		for i in range(m // 2):
			if arr[i] + arr[m - 2 - i] > 0:
				if abs(arr[i] - arr[m - 2 - i]) > 1:
					ans += abs(arr[i] - arr[m - 2 - i])
				else:
					ans += 1
		print(ans)


from collections import Counter
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	f = Counter((ai % m for ai in a))
	ans = 0
	if f[0] > 0:
		ans += 1
	for i in range(1, m // 2 + 1):
		if i == m - i:
			if f[i] > 0:
				ans += 1
		else:
			(p, q) = sorted([f[i], f[m - i]])
			if q > 0:
				if p == q:
					ans += 1
				elif p + 1 == q:
					ans += 1
				else:
					ans += 1 + (q - p - 1)
	print(ans)


t = int(input())
while t:
	t -= 1
	(n, k) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	d = {}
	for i in arr:
		if i % k not in d:
			d[i % k] = 0
		d[i % k] += 1
	if 0 in d:
		d[0] = 1
	l = list(d.keys())
	ans = 0
	for i in l:
		if d[i] == 0:
			continue
		if i == 0 or i == k - i:
			ans += 1
		elif k - i in d:
			y = d[i]
			x = d[k - i]
			ans += 1 + max(0, abs(x - y) - 1)
			d[i] = 0
			d[k - i] = 0
		else:
			ans += d[i]
	print(ans)


for u in range(int(input())):
	(n, k) = map(int, input().split())
	x = [int(w) for w in input().split()]
	cnt = [0] * k
	for i in x:
		cnt[i % k] += 1
	ans = 0
	for i in range(k // 2 + 1):
		opp = (k - i) % k
		if i == opp:
			if cnt[i] > 0:
				ans += 1
		elif cnt[i] == 0 or cnt[opp] == 0:
			ans += cnt[i] + cnt[opp]
		else:
			a = max(cnt[i], cnt[opp])
			b = min(cnt[i], cnt[opp])
			if a - b <= 1:
				ans += 1
			else:
				ans += a - b
	print(ans)


import math

def solve():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	d = [0] * m
	for i in a:
		d[i % m] += 1
	ans = 1 if d[0] > 0 else 0
	for i in range(1, m // 2 + 1):
		if min(d[i], d[m - i]) > 0:
			ans += 1
			mn = min(d[i], d[m - i])
			d[m - i] = max(0, d[m - i] - 1 - mn)
			d[i] = max(0, d[i] - 1 - min(d[i], mn))
		ans += d[i] + d[m - i]
	print(ans)
t = 1
t = int(input())
for _ in range(t):
	solve()


import math, sys
from collections import defaultdict, Counter, deque
from bisect import bisect_left, bisect_right
from itertools import permutations
INF = float('inf')
MOD = int(1000000000.0) + 7
MAX = int(1000000.0) + 5

def solve():
	(n, q) = vars()
	arr = array()
	m = defaultdict(int)
	for i in range(n):
		m[arr[i] % q] += 1
	ans = n
	b = list(m.keys())
	for k in b:
		if k == 0:
			ans -= m[k] - 1
			m[k] = 0
		elif k == q - k:
			ans -= m[k] - 1
			m[k] = 0
		else:
			if m[k] < m[q - k]:
				can = m[k]
				m[k] -= can
				m[q - k] -= can + 1
				l = 2 * can + 1
			elif m[k] > m[q - k]:
				can = m[q - k]
				m[q - k] -= can
				m[k] -= can + 1
				l = 2 * can + 1
			else:
				can = m[k]
				m[k] -= can
				m[q - k] -= can
				l = 2 * can
			if l:
				ans -= l - 1
	print(ans)

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solve()

class DisjSet:

	def __init__(self, n):
		self.rank = [1] * n
		self.parent = [i for i in range(n)]

	def find(self, x):
		if self.parent[x] != x:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def Union(self, x, y):
		xset = self.find(x)
		yset = self.find(y)
		if xset == yset:
			return
		if self.rank[xset] < self.rank[yset]:
			self.parent[xset] = yset
		elif self.rank[xset] > self.rank[yset]:
			self.parent[yset] = xset
		else:
			self.parent[yset] = xset
			self.rank[xset] = self.rank[xset] + 1

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

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

def print(*args, sep=' ', end='\n'):
	first = True
	for arg in args:
		if not first:
			sys.stdout.write(sep)
		sys.stdout.write(str(arg))
		first = False
	sys.stdout.write(end)
primes = [1 for i in range(MAX)]

def sieve():
	global primes
	primes[0] = primes[1] = 0
	i = 2
	while i <= MAX ** 0.5:
		j = i * i
		while primes[i] and j < MAX:
			if j % i == 0:
				primes[j] = 0
			j += i
		i += 1

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

def array():
	return list(vars())
main()


import os
import sys
import math
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 dijkstra(start, distance, path, n):
	visited = [False for _ in range(n)]
	distance[start] = 0
	for i in range(n):
		v = -1
		for j in range(n):
			if not visited[v] and (v == -1 or distance[j] < distance[v]):
				v = j
		if distance[v] == math.inf:
			break
		visited[v] = True
		for edge in adj[v]:
			destination = edge[0]
			weight = edge[1]
			if distance[v] + weight < distance[destination]:
				distance[destination] = distance[v] + weight
				path[destination] = v

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

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

def ncr(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def npr(n, r):
	return math.factorial(n) // math.factorial(n - r)

def seive(n):
	primes = [True] * (n + 1)
	ans = []
	for i in range(2, n):
		if not primes[i]:
			continue
		j = 2 * i
		while j <= n:
			primes[j] = False
			j += i
	for p in range(2, n + 1):
		if primes[p]:
			ans += [p]
	return ans

def factors(n):
	factors = []
	x = 1
	while x * x <= n:
		if n % x == 0:
			if n // x == x:
				factors.append(x)
			else:
				factors.append(x)
				factors.append(n // x)
		x += 1
	return factors

def main():
	try:
		for _ in range(inp()):
			(n, m) = invr()
			a = inlt()
			d = {x: 0 for x in range(m)}
			c = 0
			for i in range(n):
				d[a[i] % m] += 1
			for i in range(m // 2 + 1):
				if i == 0 and d[i] != 0:
					c += 1
					d[i] = 0
					continue
				elif i == 0:
					continue
				if i == m - i and d[i] != 0:
					c += 1
					d[i] = 0
					d[m - i] = 0
					continue
				if d[i] != 0 and d[m - i] != 0:
					if d[i] < d[m - i]:
						d[m - i] -= d[i] + 1
						d[i] = 0
						c += 1 + d[m - i]
						d[m - i] = 0
						continue
					elif d[i] > d[m - i]:
						d[i] -= d[m - i] + 1
						d[m - i] = 0
						c += 1 + d[i]
						d[i] = 0
						continue
					else:
						c += 1
						d[i] = 0
						d[m - i] = 0
						continue
				elif d[i] != 0:
					c += d[i]
					d[i] = 0
					continue
				elif d[m - i] != 0:
					c += d[m - i]
					d[m - i] = 0
					continue
				pass
			print(c)
	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()


import sys
from collections import Counter

def read_ints():
	return [int(i) for i in sys.stdin.readline().strip().split()]

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

def nsubs(m, arr):
	c = Counter((a % m for a in arr))
	subs = 0
	seen = set()
	for (k, val1) in c.items():
		if k == 0:
			subs += 1
		else:
			k2 = m - k
			if k2 in seen:
				continue
			val2 = c.get(k2, 0)
			if val1 > val2:
				(val1, val2) = (val2, val1)
			if val2 - val1 <= 1:
				subs += 1
			else:
				subs += 1 + (val2 - val1 - 1)
		seen.add(k)
	return subs
t = read_int()
for i in range(t):
	(n, m) = read_ints()
	arr = read_ints()
	print(nsubs(m, arr))


import logging
import sys
from collections import Counter
from inspect import currentframe
input = sys.stdin.readline
logging.basicConfig(level=logging.DEBUG)

def dbg(*args):
	id2names = {id(v): k for (k, v) in currentframe().f_back.f_locals.items()}
	logging.debug(', '.join((id2names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args)))

def solve():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	ra = [ai % m for ai in a]
	c = Counter(ra)
	ans = 0
	for (k, v) in c.items():
		if k == 0:
			ans += 1
		elif k * 2 == m:
			ans += 1
		elif not m - k in c:
			ans += v
		elif m - k in c:
			if k >= m - k:
				continue
			if abs(v - c[m - k]) <= 1:
				ans += 1
			else:
				ans += abs(v - c[m - k])
	return ans

def main():
	t = int(input())
	for _ in range(t):
		print(solve())
main()


from collections import defaultdict
t = int(input())

def fun():
	count = 0
	res = 0
	for i in s:
		j = m - i
		if counted[i] == 1:
			continue
		counted[i] = 1
		if j in dict:
			counted[j] = 1
			res += 1
		if i == j or i == 0:
			count += 1
			res += 1
		elif j not in dict:
			res += 1
			count += dict[i]
		else:
			res += 1
			ans = abs(dict[i] - dict[j])
			res += 1
			if ans <= 1:
				count += 1
			else:
				count += ans
	return count
res = 0
for i in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	counted = defaultdict(int)
	dict = defaultdict(int)
	for i in l:
		dict[i % m] += 1
	res += 1
	s = set(dict.keys())
	answer = fun()
	print(answer)


def solve():
	freq = [0] * m
	for i in range(n):
		freq[arr[i] % m] += 1
	ans = 1 if freq[0] else 0
	i = 1
	j = m - 1
	while i <= j:
		mi = min(freq[i], freq[j])
		ma = max(freq[i], freq[j])
		if mi or ma:
			if ma != mi:
				ans += ma - mi
			else:
				ans += 1
		i += 1
		j -= 1
	return ans
q = int(input())
while q:
	(n, m) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	print(solve())
	q -= 1


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	(d, v) = ({}, {})
	for i in range(n):
		if a[i] % m not in d:
			d[a[i] % m] = 1
		else:
			d[a[i] % m] += 1
		a[i] = a[i] % m
	ans = 0
	for i in range(n):
		if a[i] in d and d[a[i]] > 0:
			x = a[i]
			y = a[i]
			d[a[i]] -= 1
			ans += 1
			while (m - y) % m in d and d[(m - y) % m] > 0:
				d[(m - y) % m] -= 1
				y = (m - y) % m
			while (m - x) % m in d and d[(m - x) % m] > 0:
				d[(m - x) % m] -= 1
				x = (m - x) % m
	print(ans)


import sys
import math
import bisect
import heapq
from bisect import bisect_right
from sys import stdin, stdout

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

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

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

def get_list_of_list(n):
	return [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]

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

def Solution(arr, n, m):
	ans = 0
	hm = {}
	for i in range(m):
		hm[i] = 0
	for i in range(n):
		hm[arr[i] % m] += 1
	if hm[0] >= 1:
		ans += 1
	for i in range(1, m):
		if hm[i]:
			if abs(hm[i] - hm[m - i]) <= 1:
				ans += 1
			else:
				ans += abs(hm[i] - hm[m - i])
			hm[m - i] = 0
	print(ans)

def main():
	for _ in range(get_int()):
		(n, m) = get_ints_in_variables()
		arr = get_ints_in_list()
		Solution(arr, n, m)
main()


from collections import Counter

def read_int():
	return int(input())

def read_ints():
	return map(int, input().split(' '))
t = read_int()
for case_num in range(t):
	(n, m) = read_ints()
	cnt = Counter((i % m for i in read_ints()))
	ans = 0
	if cnt[0] > 0:
		ans += 1
	if m % 2 == 0 and cnt[m // 2] > 0:
		ans += 1
	for i in range(1, (m + 1) // 2):
		if cnt[i] > 0 or cnt[m - i] > 0:
			ans += 1
			if abs(cnt[i] - cnt[m - i]) > 1:
				ans += abs(cnt[i] - cnt[m - i]) - 1
	print(ans)


def find():
	(n, m) = map(int, input().split())
	mas = list(map(int, input().split()))
	ost = {}
	for j in mas:
		o = j % m
		if o > m // 2:
			ost[m - o] = ost.get(m - o, 0) - 1
		else:
			ost[o] = ost.get(o, 0) + 1
	ans = 0
	for j in ost:
		if j == 0 or j == m / 2:
			ans += 1
		else:
			ans += max(abs(ost[j]), 1)
	return ans
for i in range(int(input())):
	print(find())


from collections import Counter
nn = int(input())
for _ in range(nn):
	(n, m) = [int(s) for s in input().split()]
	l = [int(s) for s in input().split()]
	c = Counter([e % m for e in l])
	res = 0
	if c[0] > 0:
		res += 1
	if m % 2 == 0 and c[m // 2] > 0:
		res += 1
	for k in range(1, (m + 1) // 2):
		if c[k] > 0 and c[m - k] > 0 and (c[k] == c[m - k]):
			res += 1
		else:
			res += abs(c[k] - c[m - k])
	print(res)


x = int(input())
for i in range(x):
	(n, k) = [int(a) for a in input().split()]
	ar = list(map(int, input().split()))
	b = [0] * k
	for j in range(n):
		b[ar[j] % k] = b[ar[j] % k] + 1
	d = 1
	e = k - 1
	s = 0
	while d <= e:
		if b[d] == b[e] and b[d] != 0:
			s = s + 1
		else:
			s = s + abs(b[d] - b[e])
		d = d + 1
		e = e - 1
	if b[0] > 0:
		s = s + 1
	print(s)


def Solve():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = [0] * m
	for i in range(len(a)):
		b[a[i] % m] += 1
	if b[0] > 0:
		x = 1
		b[0] = 0
	else:
		x = 0
	i = 1
	j = m - 1
	while i <= j:
		if b[i] > 0 or b[j] > 0:
			x += 1
			mi = min(b[i], b[j])
			ma = max(b[i], b[j])
			if ma - mi > 1:
				x += ma - (mi + 1)
		i += 1
		j -= 1
	print(x)
q = int(input())
while q:
	Solve()
	q -= 1


import sys
from collections import defaultdict, Counter as CC
from math import sqrt, ceil, floor, log2
INF = float('inf')
MOD = 10 ** 9 + 7
read = lambda : [int(s) for s in sys.stdin.readline().split()]

def solve():
	(n, m) = read()
	a = read()
	cnt = [0] * m
	for i in a:
		cnt[i % m] += 1
	res = 0
	if cnt[0] > 0:
		res += 1
	if m % 2 == 0 and cnt[m // 2] > 0:
		res += 1
	for i in range(1, ceil(m / 2)):
		tm = min(cnt[i], cnt[m - i])
		if tm > 0:
			res += 1
			cnt[i] -= tm
			cnt[m - i] -= tm
			if cnt[i] > 0:
				cnt[i] -= 1
			elif cnt[m - i] > 0:
				cnt[m - i] -= 1
		res += cnt[i] + cnt[m - i]
	print(res)
_ = 1
_ = int(input())
while _:
	solve()
	_ -= 1


answers = []

def solve(n, m, arr):
	if n == 1:
		answers.append(1)
		return
	count = 0
	store = {}
	for ele in arr:
		rem = ele % m
		if rem not in store:
			store[rem] = 1
		else:
			store[rem] += 1
	if 0 in store:
		count = 1
	start = 1
	end = m - 1
	while start <= end:
		count1 = 0
		count2 = 0
		if start in store:
			count1 = store[start]
		if end in store:
			count2 = store[end]
		if count1 == 0 or count2 == 0:
			count += max(count1, count2)
		else:
			diff = abs(count1 - count2)
			if diff < 2:
				count += 1
			else:
				least = min(count1, count2)
				best = max(count1, count2)
				count += 1
				best -= least
				best -= 1
				count += best
		start += 1
		end -= 1
	answers.append(count)
T = int(input())
while T:
	(n, m) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	solve(n, m, arr)
	T -= 1
for ans in answers:
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	c = 0
	freq = [0 for i in range(m)]
	for i in arr:
		freq[i % m] += 1
	if freq[0] > 0:
		c = 1
	for i in range(1, m):
		if freq[i] != 0:
			if freq[m - i] != 0:
				diff = abs(freq[i] - freq[m - i])
				if diff <= 1:
					c += 1
				else:
					c += diff
				freq[m - i] = 0
			else:
				c += freq[i]
			freq[i] = 0
	print(c)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	rem = [0] * m
	for i in range(n):
		rem[a[i] % m] += 1
	p = (rem[0] > 0) * 1
	tot = rem[0]
	for i in range(1, (m + 1) // 2):
		f = min(rem[i], rem[m - i])
		p += (f > 0) * 1
		tot += 2 * f + (rem[i] != rem[m - i]) * (f > 0)
	if m & 1 == 0:
		f = rem[m // 2] > 0
		p += f
		tot += rem[m // 2]
	print(p + n - tot)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	narr = [0 for _ in range(m)]
	for i in arr:
		narr[i % m] += 1
	ans = 0
	if narr[0]:
		ans += 1
		narr[0] = 0
	if m % 2 == 0 and narr[m // 2]:
		ans += 1
		narr[m // 2] = 0
	for i in range(1, m // 2 + 1):
		if narr[i] and narr[m - i]:
			if narr[i] > narr[m - i]:
				narr[i] -= narr[m - i] + 1
				narr[m - i] = 0
			elif narr[i] < narr[m - i]:
				narr[m - i] -= narr[i] + 1
				narr[i] = 0
			else:
				narr[m - i] = 0
				narr[i] = 0
			ans += 1
	print(ans + sum(narr))


for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	g = [0] * (m + 1)
	for j in range(n):
		g[a[j] % m] = g[a[j] % m] + 1
	sumo = 0
	for j in range(1, (m + 1) // 2):
		if min(g[j], g[m - j]) == max(g[j], g[m - j]) and min(g[j], g[m - j]) > 0:
			sumo = sumo + 1
		else:
			sumo = sumo + max(g[j], g[m - j]) - min(g[j], g[m - j])
	if m % 2 == 0:
		if g[m // 2] > 0:
			sumo = sumo + 1
	if g[0] > 0:
		sumo = sumo + 1
	print(sumo)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	x = [0] * (m + 1)
	for i in range(n):
		l[i] = l[i] % m
		x[l[i]] += 1
	l.sort()
	ans = 0
	if x[0] > 0:
		ans += 1
	for i in range(1, m):
		if i == m - i:
			if x[i] > 0:
				ans += 1
			x[i] = 0
			continue
		z = x[i]
		z1 = x[m - i]
		mi = min(z, z1)
		if mi > 0:
			ans += 1
			z -= mi
			z1 -= mi
		else:
			ans += x[i]
			ans += x[m - i]
			z = 0
			z1 = 0
		if z > 0:
			z -= 1
		if z1 > 0:
			z1 -= 1
		ans += z1
		ans += z
		x[i] = 0
		x[m - i] = 0
	print(ans)


def max(x, y):
	if x == y and y == 0:
		return 0
	if x >= y + 1:
		return x - y
	elif y >= x + 1:
		return y - x
	return 1

def zero(a):
	if a > 0:
		return 1
	return 0

def MMM(n, m, a):
	D = [0] * m
	for i in range(n):
		D[a[i] % m] += 1
	total = 0
	if m % 2 == 0:
		total += zero(D[0]) + zero(D[m // 2])
		for i in range(1, m // 2):
			total += max(D[i], D[m - i])
	else:
		total += zero(D[0])
		for i in range(1, (m + 1) // 2):
			total += max(D[i], D[m - i])
	print(total)
	return 0
t = int(input())
for p in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	MMM(n, m, a)


import math
from collections import *
import math

def solve():
	(n, m) = map(int, input().split())
	x = [int(i) for i in input().split()]
	a = [0] * m
	for i in range(n):
		a[x[i] % m] += 1
	c = 0
	for i in range(1, m // 2 + 1):
		if a[i] == a[m - i]:
			if a[i] != 0 and a[m - i] != 0:
				c += 1
		elif a[i] > a[m - i]:
			a[i] -= a[m - i] + 1
			c += a[i] + 1
		else:
			a[m - i] -= a[i] + 1
			c += a[m - i] + 1
	if a[0] != 0:
		print(c + 1)
	else:
		print(c)
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	d = {}
	for i in range(n):
		mod = arr[i] % m
		if mod in d:
			d[mod] += 1
		else:
			d[mod] = 1
	ans = 0
	vis = {}
	for i in d:
		if i not in vis:
			if i == 0:
				ans += 1
			elif m - i not in d:
				ans += d[i]
			else:
				r = d[m - i]
				c = d[i]
				if r == c - 1 or r == c:
					ans += 1
				else:
					ans += abs(c - r)
				vis[m - i] = None
	print(ans)


import math
import sys
import collections
import bisect
import heapq
testcases = int(sys.stdin.readline())
for _ in range(testcases):
	arr = list(map(int, sys.stdin.readline().strip().split()))
	n = arr[0]
	m = arr[1]
	arr = list(map(int, sys.stdin.readline().strip().split()))
	d = {}
	for i in arr:
		mod = i % m
		if mod in d:
			d[mod] += 1
		else:
			d[mod] = 1
	res = 0
	curr = []
	act = True
	for i in d:
		if d[i] != 0:
			if i == 0:
				res += 1
			else:
				x1 = d[i]
				if m - i in d:
					x2 = d[m - i]
					if abs(x1 - x2) <= 1:
						res += 1
						d[i] = 0
						d[m - i] = 0
					else:
						res += abs(x1 - x2)
						d[i] = 0
						d[m - i] = 0
				else:
					res += x1
					d[i] = 0
	print(res)


import sys
from collections import Counter
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	div_dict = Counter()
	for num in arr:
		div_dict[num % m] += 1
	ans = 0
	visited = set()
	for k in div_dict:
		if k in visited:
			continue
		visited.add(k)
		if k == 0:
			ans += 1
		elif m - k in div_dict:
			visited.add(m - k)
			if m - k == k:
				ans += 1
			else:
				ans += max(1, max(div_dict[k], div_dict[m - k]) - min(div_dict[k], div_dict[m - k]))
		else:
			ans += div_dict[k]
	print(ans)
sys.exit()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	moda = []
	modc = [0] * (m + 1)
	ans = 0
	for i in range(n):
		if a[i] % m != 0:
			moda.append(a[i] % m)
			modc[a[i] % m] += 1
	if len(moda) != n:
		ans += 1
	if 1:
		moda = list(set(moda))
		moda.sort()
		i = 0
		j = len(moda) - 1
		while i <= j:
			if i == j and moda[i] + moda[j] != m:
				ans += modc[moda[i]]
				i += 1
				j -= 1
			elif moda[i] + moda[j] == m:
				if abs(modc[moda[i]] - modc[moda[j]]) > 1:
					ans += abs(modc[moda[i]] - modc[moda[j]]) - 1
				i += 1
				j -= 1
				ans += 1
			elif moda[i] + moda[j] > m:
				if moda[j] == int(m / 2):
					ans += 1
				else:
					ans += modc[moda[j]]
				j -= 1
			else:
				if moda[i] == int(m / 2):
					ans += 1
				else:
					ans += modc[moda[i]]
				i += 1
		print(ans)


import collections
for t in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	ans = []
	for i in arr:
		ans.append(i % m)
	counter = collections.Counter(ans)
	val = 0
	for i in counter:
		if counter[i] == 0:
			continue
		if i == 0:
			counter[i] = 0
			val += 1
		else:
			comp = m - i
			if comp not in counter:
				val += counter[i]
				counter[i] = 0
				continue
			if comp == i:
				val += 1
				counter[i] = 0
			else:
				if abs(counter[i] - counter[comp]) >= 1:
					minim = min(counter[i], counter[comp]) + 1
				else:
					minim = min(counter[i], counter[comp])
				val += 1
				counter[comp] -= min(minim, counter[comp])
				counter[i] -= min(minim, counter[i])
				if counter[i] > 0:
					val += counter[i]
					counter[i] = 0
	print(val)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	d = [0] * m
	for i in map(int, input().split()):
		d[i % m] += 1
	if d[0] > 0:
		c = 1
	else:
		c = 0
	for i in range(1, m // 2 + 1):
		(a, b) = (d[i], d[m - i])
		if a == b == 0:
			continue
		elif a == b:
			c += 1
			continue
		e = abs(a - b)
		if e == 1:
			c += 1
		else:
			c += e
	print(c)


from collections import Counter

def getLine():
	return map(int, input().split())
for i in range(int(input())):
	(n, m) = getLine()
	ar = [*getLine()]
	ar = [i % m for i in ar]
	cnt = Counter(ar)
	res = 0
	for i in ar:
		if i == 0:
			if cnt[i]:
				res += 1
				cnt[i] = 0
		elif cnt[i]:
			res += 1
			tmp = [i, i]
			cnt[i] -= 1
			while cnt[m - tmp[0]] or cnt[m - tmp[-1]]:
				if cnt[m - tmp[-1]]:
					cnt[m - tmp[-1]] -= 1
					tmp[1] = m - tmp[-1]
				elif cnt[m - tmp[0]]:
					cnt[m - tmp[0]] -= 1
					tmp[0] = m - tmp[0]
	print(res)


for _ in range(int(input())):
	(n, m) = [int(x) for x in input().split(' ')]
	a = [int(x) for x in input().split(' ')]
	cnt = [0] * m
	for v in a:
		cnt[v % m] += 1
	ans = 0
	if cnt[0] >= 1:
		ans += 1
	for i in range(1, m):
		if cnt[i] == 0:
			continue
		if cnt[i] >= 1 and cnt[m - i] >= 1:
			if cnt[i] == cnt[m - i]:
				ans += 1
			else:
				max_v = max(cnt[i], cnt[m - i])
				min_v = min(cnt[i], cnt[m - i])
				if max_v == min_v + 1:
					ans += 1
				else:
					ans += max_v - min_v
			cnt[i] = 0
			cnt[m - i] = 0
		else:
			ans += cnt[i]
	print(ans)


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

def main():
	t = int(input())
	for i in range(t):
		(n, m) = map(int, input().split())
		a = list(map(int, input().split()))
		for i in range(len(a)):
			a[i] = a[i] % m
		d = Counter(a)
		ans = 0
		if d[0] == n:
			print(1)
		else:
			for i in range(1, m // 2 + 1):
				if d[i] == d[m - i]:
					if d[i] > 0 and d[m - i] > 0:
						ans += 1
						d[i] = 0
						d[m - i] = 0
				elif d[i] < d[m - i]:
					if d[i] > 0:
						ans += 1
						d[m - i] -= d[i] + 1
						d[i] = 0
					if d[m - i] > 0:
						ans += d[m - i]
						d[m - i] = 0
					else:
						d[m - i] = 0
				else:
					if d[m - i] > 0:
						ans += 1
						d[i] -= d[m - i] + 1
						d[m - i] = 0
					if d[i] > 0:
						ans += d[i]
						d[i] = 0
					else:
						d[i] = 0
			if d[0] > 0:
				print(ans + 1)
			else:
				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
for t in range(int(input())):
	(n, m) = map(int, input().split())
	aaa = list(map(int, input().split()))
	dic = defaultdict(int)
	for i in aaa:
		dic[i % m] += 1
	ans = 0
	for i in range(0, m):
		if i == 0 and dic[i] > 0:
			ans += 1
		elif m - i not in dic:
			ans += dic[i]
		elif m - i == i:
			ans += 1
		elif m - i > i:
			a = dic[i]
			b = dic[m - i]
			if abs(b - a) <= 1:
				ans += 1
			elif a > b:
				a -= b + 1
				ans += 1
				ans += a
			else:
				b -= a + 1
				ans += 1
				ans += b
	print(ans)


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

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

def solve(arr, n, m):
	(count1, count2) = (0, 0)
	helper = dict()
	for i in arr:
		if i % m == 0:
			count1 = 1
		elif m % 2 == 0 and i % m == m // 2:
			count2 = 1
		else:
			helper[i % m] = helper.get(i % m, 0) + 1
	(i, j) = (1, m - 1)
	answer = count1 + count2
	while i < j:
		x = helper.get(i, 0)
		y = helper.get(j, 0)
		if x == 0 or y == 0:
			answer += max(x, y)
		elif x == y:
			answer += 1
		else:
			answer += abs(x - y)
		i += 1
		j -= 1
	return answer
t = int(input().decode())
while t > 0:
	s = input().decode().strip().split()
	(n, m) = (int(s[0]), int(s[1]))
	arr = [int(i) for i in input().decode().strip().split()]
	answer = solve(arr, n, m)
	sys.stdout.write(str(answer) + '\n')
	t -= 1


test_num = int(input())

def solve():
	(n, m) = map(int, input().split())
	array = list(map(int, input().split()))
	mod = [0] * m
	for a in array:
		mod[a % m] += 1
	ans = mod[0] > 0 and 1 or 0
	for i in range(1, m // 2 + 1):
		num1 = max(mod[i], mod[m - i])
		num2 = min(mod[i], mod[m - i])
		if num1 == 0:
			continue
		ans += 1 + max(0, num1 - num2 - 1)
	print(ans)
for i in range(test_num):
	solve()


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
from functools import lru_cache
int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
aj = lambda : list(map(int, input().split()))

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

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, m) = aj()
	A = aj()
	A = [i % m for i in A]
	C = Counter(A)
	count = 0
	for i in A:
		if i == 0:
			if C[i]:
				count += 1
				C[i] = 0
		elif C[i]:
			count += 1
			B = [i, i]
			C[i] -= 1
			while C[m - B[-1]] or C[m - B[0]]:
				if C[m - B[-1]]:
					C[m - B[-1]] -= 1
					B[1] = m - B[-1]
				elif C[m - B[0]]:
					C[m - B[0]] -= 1
					B[0] = m - B[0]
	print(count)


import sys
from math import ceil, floor, sqrt
from collections import defaultdict

def read_generator():
	while True:
		tokens = sys.stdin.readline().rstrip().split(' ')
		for t in tokens:
			yield t
reader = read_generator()

def read():
	return next(reader)

def readint():
	return int(next(reader))

def readfloat():
	return float(next(reader))

def readline():
	return input()

def readlistint(n):
	return [readint() for _ in range(n)]

def readliststr(n):
	return [read() for _ in range(n)]

def readlistfloat(n):
	return [readfloat() for _ in range(n)]

def zfunc(s):
	z = [0] * len(s)
	l = 0
	r = 0
	for i in range(1, len(s)):
		if i <= r:
			z[i] = min(z[i - l], r - i + 1)
		while i + z[i] < len(s) and s[z[i]] == s[i + z[i]]:
			z[i] += 1
		if r < i + z[i] - 1:
			l = i
			r = i + z[i] - 1
	return z

def solve(a, m):
	c = [0] * (m + 1)
	for v in a:
		c[v] += 1
	res = 0
	for i in range(m):
		if c[i] == 0:
			continue
		if i == 0 or i + i == m:
			res += 1
			continue
		if i + i == m:
			res += 1
			continue
		ma = max(c[i], c[m - i])
		mi = min(c[i], c[m - i])
		res += max(1, ma - mi)
		c[i] = 0
		c[m - i] = 0
	return res
tests = readint()
for test in range(1, tests + 1):
	n = readint()
	m = readint()
	a = list(map(lambda it: it % m, readlistint(n)))
	print(solve(a, m))


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


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = [0] * m
	for i in a:
		b[i % m] += 1
	if len(a) == 1 or m == 1:
		print(1)
	else:
		ans = 0
		if b[0] > 0:
			ans = 1
		for i in range(1, m // 2 + 1):
			if abs(b[i] - b[m - i]) <= 1 and (b[i] > 0 or b[m - i] > 0):
				ans += 1
			else:
				ans += 1 + (max(b[i], b[m - i]) - (min(b[i], b[m - i]) + 1))
		print(ans)


def find_arrays(m, arr):
	ans_dict = {}
	for i in range(m):
		ans_dict[i] = 0
	for num in arr:
		rem = num % m
		ans_dict[rem] += 1
	ans = 0
	for i in range(1, m // 2 + 1):
		x = ans_dict[i]
		y = ans_dict[m - i]
		if x == y:
			if x:
				ans += 1
		else:
			ans += abs(x - y)
	if ans_dict[0] > 0:
		ans += 1
	return ans
test_cases = int(input())
ans = []
for _ in range(test_cases):
	(n, m) = map(int, input().split())
	arr = map(int, input().split())
	ans.append(find_arrays(m, arr))
for i in ans:
	print(i)


q = int(input())
while q:
	(n, m) = map(int, input().split())
	A = list(map(lambda x: int(x) % m, input().split()))
	B = [0] * m
	ans = 0
	for i in range(n):
		B[A[i]] += 1
	for i in range(1, m):
		if B[i] == 0 and B[m - i] == 0:
			continue
		if m % 2 == 0 and i == m // 2:
			if B[i] > 0:
				ans += 1
			B[i] = 0
			continue
		if abs(B[i] - B[m - i]) <= 1:
			ans += 1
		else:
			ans += 1
			if B[i] < B[m - i]:
				B[m - i] -= B[i] + 1
				ans += B[m - i]
			else:
				B[i] -= B[m - i] + 1
				ans += B[i]
		(B[i], B[m - i]) = (0, 0)
	if B[0] > 0:
		ans += 1
	print(ans)
	q -= 1


from sys import stdin
from collections import defaultdict
input = stdin.readline
T = int(input())
for t in range(1, T + 1):
	(n, m) = map(int, input().split())
	count = defaultdict(lambda : 0)
	_input = list(map(int, input().split()))
	for i in _input:
		count[i % m] += 1
	res = 0
	res += count[0] > 0
	l = 1
	r = m - 1
	while l <= r:
		if l == r:
			if count[l] > 0:
				res += 1
		elif count[l] == count[r]:
			res += count[l] > 0
		else:
			res += max(count[l], count[r]) - min(count[l], count[r])
		l += 1
		r -= 1
	print(res)


import sys
input = sys.stdin.readline
from collections import *
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	cnt = defaultdict(int)
	for i in range(n):
		cnt[a[i] % m] += 1
	ans = 0
	if cnt[0] > 0:
		ans += 1
	for i in range(1, (m + 1) // 2):
		mi = min(cnt[i], cnt[m - i])
		ma = max(cnt[i], cnt[m - i])
		if ma == 0:
			ans += 0
		elif mi == ma:
			ans += 1
		elif ma > mi:
			ans += ma - mi
	if m % 2 == 0 and cnt[m // 2] > 0:
		ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	lis = list(map(int, input().split()))
	if len(lis) == 1:
		print(1)
	else:
		dic = {}
		for i in range(m):
			dic[i] = 0
		for i in range(n):
			dic[lis[i] % m] += 1
		if dic[0] > 0:
			ans = 1
		else:
			ans = 0
		for i in range(1, m // 2 + 1):
			if dic[i] == dic[m - i]:
				if dic[i] > 0:
					ans += 1
			elif dic[i] > dic[m - i]:
				if dic[m - i] == 0:
					ans += dic[i]
				else:
					ans += 1
					a = dic[i] - (dic[m - i] + 1)
					ans += a
			elif dic[i] == 0:
				ans += dic[m - i]
			else:
				ans += 1
				a = dic[m - i] - (dic[i] + 1)
				ans += a
		print(ans)


import math
import sys
input = sys.stdin.readline
t = int(input())
for i1 in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	l2 = [0] * m
	for i in l:
		p = i % m
		l2[p] += 1
	cnt = 0
	if l2[0] > 0:
		cnt += 1
	m1 = math.floor(m / 2)
	for i in range(1, m1 + 1):
		if l2[i] > 0:
			if l2[i] == l2[m - i] or abs(l2[i] - l2[m - i]) == 1:
				cnt += 1
			else:
				p = abs(l2[i] - l2[m - i]) - 1
				cnt += p + 1
		elif l2[m - i] > 0:
			cnt += l2[m - i]
	print(cnt)


t = int(input())
for i in range(t):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	count = 0
	b = 0
	d = [0] * m
	a = list(map(int, input().split()))
	for i in range(n):
		d[a[i] % m] += 1
	if d[0] > 0:
		count += 1
	for i in range(1, (m + 1) // 2):
		if d[i] or d[m - i]:
			count += max(1, abs(d[i] - d[m - i]))
	if m % 2 == 0 and d[m // 2]:
		count += 1
	print(count)


import sys
from collections import Counter
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = sys.stdin.readline
T = int(input())
while T:
	T -= 1
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = a[i] % m
	c = Counter(a)
	ans = 0
	zero = False
	for i in range(1, m // 2 + 1):
		other = m - i
		if i not in c:
			if other in c:
				ans += c[other]
			continue
		if other not in c:
			if i in c:
				ans += c[i]
			continue
		if i == other:
			ans += 1
			zero = True
		else:
			(cnta, cntb) = (c[i], c[other])
			diff = max(cnta, cntb) - min(cnta, cntb)
			ans += diff + int(diff == 0)
			zero = True
	ans += int(0 in c)
	print(ans)


I = lambda : map(int, input().split())
for _ in [0] * int(input()):
	(n, m) = I()
	a = list(I())
	d = {}
	for i in a:
		x = i % m
		if x not in d:
			d[x] = 1
			if m - x not in d:
				d[m - x] = 0
		else:
			d[x] = d[x] + 1
	op = int(0 in d)
	for i in range(1, m // 2 + 1, 1):
		if i in d:
			x = m - i
			dif = abs(d[x] - d[i])
			if dif > 1:
				op = op + dif
			else:
				op = op + 1
	print(op)


import math
t = int(input())
for test in range(0, t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	mod = [0] * m
	for i in range(0, n):
		mod[a[i] % m] += 1
	ans = 0
	if mod[0] != 0:
		ans += 1
	ind = int(m / 2)
	if m & 1:
		ind += 1
	for i in range(1, ind):
		d = min(mod[i], mod[m - i])
		if d == 0:
			ans += max(mod[i], mod[m - i])
		elif abs(mod[i] - mod[m - i]) > 1:
			ans += max(mod[i], mod[m - i]) - d
		elif abs(mod[i] - mod[m - i]) <= 1:
			ans += 1
	if not m & 1 and mod[ind] != 0:
		ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	lst = list(map(int, input().split()))
	arr = [0] * m
	for i in lst:
		arr[i % m] += 1
	count = int(arr[0] != 0)
	for i in range(1, m // 2 + 1):
		if arr[i] != 0 or arr[m - i] != 0:
			(low, high) = (min(arr[i], arr[m - i]), max(arr[i], arr[m - i]))
			if low == high - 1 or low == high:
				count += 1
			else:
				count += high - low
	print(count)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	for i in a:
		if i % m in d:
			d[i % m] += 1
		else:
			d[i % m] = 1
	cnt = 0
	for i in d:
		if d[i] == 0:
			continue
		if i == 0:
			cnt += 1
			d[i] = 0
		if m - i in d and d[m - i] != 0:
			if m % 2 == 0 and i == m // 2:
				cnt += 1
				d[i] = 0
			elif abs(d[i] - d[m - i]) <= 1:
				cnt += 1
				d[i] = 0
				d[m - i] = 0
			else:
				x = min(d[i], d[m - i])
				if d[i] == x:
					d[i] = 0
					d[m - i] -= x + 1
					cnt += 1
				else:
					d[m - i] = 0
					d[i] -= x + 1
					cnt += 1
	for i in d:
		cnt += d[i]
	print(cnt)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	for i in range(len(A)):
		A[i] = A[i] % m
	A.sort()
	D = {}
	for i in A:
		if i in D:
			D[i] += 1
		else:
			D[i] = 1
	L = list(set(A))
	L.sort()
	i = 0
	j = len(L) - 1
	count = 0
	if L[0] == 0:
		count += 1
		i += 1
	while i <= j:
		if L[i] + L[j] == m:
			count += max(D[L[i]], D[L[j]]) - min(D[L[i]], D[L[j]])
			if max(D[L[i]], D[L[j]]) == min(D[L[i]], D[L[j]]):
				count += 1
			i += 1
			j -= 1
		elif L[i] + L[j] > m:
			count += D[L[j]]
			j -= 1
		else:
			count += D[L[i]]
			i += 1
	print(count)


for tc in range(int(input())):
	(N, M) = map(int, input().split())
	A = list(map(int, input().split()))
	modCount = [0] * M
	for i in A:
		modCount[i % M] += 1
	ans = 1 if modCount[0] else 0
	for i in range(1, M):
		while modCount[i]:
			j = (M - i) % M
			if i == j:
				ans += 1
				modCount[i] = 0
			elif modCount[j] == 0:
				ans += modCount[i]
				modCount[i] = 0
			elif modCount[j] == modCount[i]:
				modCount[i] = modCount[j] = 0
				ans += 1
			elif modCount[j] > modCount[i]:
				modCount[j] -= modCount[i] + 1
				modCount[i] = 0
				ans += 1
			elif modCount[j] < modCount[i]:
				modCount[i] -= modCount[j] + 1
				modCount[j] = 0
				ans += 1
	print(ans)


import sys
input = sys.stdin.readline
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right, bisect_left
import math
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import PriorityQueue as pq
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	x = dc(int)
	t = []
	for i in l:
		x[i % m] += 1
		if x[i % m] == 1:
			t.append(i % m)
	c = 0
	for i in t:
		p = m - i
		if x[i] > 0:
			p = m - i
			if x[p] == 0:
				if i == 0:
					x[i] = 0
					c += 1
				else:
					c += x[i]
					x[i] = 0
			elif p != i:
				if x[i] == x[p]:
					c += 1
					x[i] = 0
					x[p] = 0
				elif x[i] > x[p]:
					c += 1
					x[i] = x[i] - x[p] - 1
					x[p] = 0
					c += x[i]
					x[i] = 0
				else:
					c += 1
					x[p] = x[p] - x[i] - 1
					x[i] = 0
					c += x[p]
					x[p] = 0
			else:
				x[i] = 0
				c += 1
	print(c)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	ans = 0
	b = []
	d1 = {}
	for i in range(n):
		if a[i] % m != 0:
			try:
				d1[a[i] % m] += 1
			except:
				d1[a[i] % m] = 1
		else:
			ans = 1
	for i in d1:
		try:
			if d1[i] > d1[abs(m - i)]:
				d1[i] -= d1[abs(m - i)] + 1
				d1[abs(m - i)] = 0
				ans += 1
			elif d1[i] < d1[abs(m - i)]:
				d1[abs(m - i)] -= d1[i] + 1
				d1[i] = 0
				ans += 1
			elif d1[i] == d1[m - i] and d1[i] != 0:
				d1[i] = 0
				d1[abs(m - i)] = 0
				ans += 1
		except:
			continue
	for i in d1:
		ans += d1[i]
	print(ans)


from collections import Counter

def solve():
	(n, m) = map(int, input().split())
	arr = map(int, input().split())
	arr = [i % m for i in arr]
	flag = [1] * m
	c = Counter(arr)
	ans = 0
	for (key, val) in c.items():
		if key == 0:
			ans += 1
		elif flag[key]:
			ans += max(0, abs(val - c[m - key]) - 1) + 1
			flag[m - key] = 0
	print(ans)
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	array = list(map(int, input().split()))
	countArray = [0] * m
	for i in range(n):
		countArray[array[i] % m] += 1
	answer = 0 if countArray[0] == 0 else 1
	for i in range(1, m // 2 + 1):
		minOf2 = min(countArray[i], countArray[m - i])
		if minOf2 != 0:
			answer += 1
			countArray[i] -= minOf2
			if i != m - i:
				countArray[m - i] -= minOf2
			if countArray[i] > 0:
				answer += countArray[i] - 1
			if countArray[m - i] > 0:
				answer += countArray[m - i] - 1
		else:
			answer += max(countArray[i], countArray[m - i])
	print(answer)


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())
mod = 1000000007

def solve(n, k, arr):
	out = [0 for i in range(k)]
	for i in range(n):
		out[arr[i] % k] += 1
	c = 0
	for i in range(k // 2 + 1):
		val = (k - i) % k
		if out[val] + out[i] > 0:
			c += max(abs(out[val] - out[i]), 1)
	print(c)
for _ in range(int(input())):
	(n, k) = get_int()
	arr = int_arr()
	solve(n, k, arr)


import sys, functools, collections, bisect, math, heapq
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().strip().split())
	arr = list(map(int, input().strip().split()))
	arr = [i % m for i in arr]
	d = collections.Counter(arr)
	ans = 0
	for i in range(1, m // 2):
		x = i
		y = m - i
		if d[x] or d[y]:
			pre = min(d[x], d[y])
			d[x] -= pre
			d[y] -= pre
			ans += 1
			ans += max(d[x] + d[y] - 1, 0)
			d[y] = 0
			d[x] = 0
	if d[0]:
		ans += 1
	if m // 2:
		x = m // 2
		y = m - x
		if x == y:
			if d[x]:
				ans += 1
		elif d[x] or d[y]:
			pre = min(d[x], d[y])
			d[x] -= pre
			d[y] -= pre
			ans += 1
			ans += max(d[x] + d[y] - 1, 0)
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	a = (m + 2) // 2
	f = []
	for i in range(m):
		f.append(0)
	for i in range(n):
		b = l[i] % m
		f[b] += 1
	if f[0] > 0:
		ans = 1
	else:
		ans = 0
	for i in range(m // 2):
		a = f[i + 1]
		b = f[m - i - 1]
		d = abs(a - b)
		if d > 1:
			ans += d
		elif a != 0 or b != 0:
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = [0] * m
	for j in a:
		b[j % m] += 1
	ans = 0
	if b[0] > 0:
		ans += 1
	for j in range(1, (m + 1) // 2):
		if b[j] or b[m - j]:
			ans += max(1, abs(b[m - j] - b[j]))
	if m % 2 == 0 and b[m // 2]:
		ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = [0] * m
	for i in a:
		b[i % m] += 1
	ans = 0
	if b[0] >= 1:
		ans += 1
	for i in range(1, m // 2 + 1):
		if b[i] == b[m - i] and b[i] != 0:
			ans += 1
		elif b[i] != 0 and b[m - i] != 0 and (b[i] == b[m - i] + 1 or b[m - i] == b[i] + 1):
			ans += 1
		elif b[i] != 0 and b[m - i] != 0:
			if b[i] > b[m - i]:
				ans += b[i] - b[m - i]
			else:
				ans += b[m - i] - b[i]
		elif b[i] != 0:
			ans += b[i]
		elif b[m - i] != 0:
			ans += b[m - i]
	print(ans)


import math
import sys
input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())
for i in range(inp()):
	(n, m) = invr()
	l = inlt()
	d = {}
	for i in range(m):
		d[i] = 0
	for i in range(n):
		d[l[i] % m] += 1
	count = 0
	for each in d:
		if each != 0 and each <= m // 2:
			if d[each] != 0 or d[m - each] != 0:
				count += max(1, abs(d[each] - d[m - each]))
		if each == 0:
			if d[each] != 0:
				count += 1
	print(count)


k = int(input())
import collections
for i in range(k):
	(num, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	lst = [i % k for i in lst]
	kk = collections.Counter(lst)
	tj = []
	ans1 = 0
	ans2 = 0
	ans3 = 0
	if 0 in kk:
		ans3 += 1
		del kk[0]
	if k % 2 == 0:
		if k // 2 in kk:
			ans3 += 1
			del kk[k // 2]
	for i in kk:
		if k - i not in kk:
			ans1 += kk[i]
		elif kk[i] == kk[k - i] or abs(kk[i] - kk[k - i]) == 1:
			ans2 += 1
		else:
			ans2 += abs(kk[i] - kk[k - i])
	print(ans1 + ans2 // 2 + ans3)


import sys
import math
import collections
input = sys.stdin.readline
t = int(input())
for w in range(t):
	(n, m) = (int(i) for i in input().split())
	l = [int(i) for i in input().split()]
	for i in range(n):
		l[i] %= m
	d = collections.Counter(l)
	c = 0
	for i in d:
		if i == 0:
			c += 1
			continue
		if d[i] != -1:
			if m - i in d:
				c += 1
				if d[i] > d[m - i]:
					c += d[i] - d[m - i] - 1
				elif d[i] < d[m - i]:
					c += d[m - i] - d[i] - 1
				d[m - i] = -1
				d[i] = -1
			else:
				c += d[i]
				d[i] = -1
	print(c)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if m == 1:
		print(1)
		continue
	d = [0] * m
	for x in a:
		d[x % m] = d[x % m] + 1
	ans = 0
	if d[0] > 0:
		ans = ans + 1
	for i in range(1, m // 2 + 1):
		if (d[i] != 0) & (d[m - i] != 0) & (abs(d[i] - d[m - i]) <= 1):
			ans = ans + 1
		else:
			ans = ans + abs(d[i] - d[m - i])
	print(ans)


k = int(input())
ans = []
for i in range(k):
	(n, m) = map(int, input().split())
	mass = list(map(int, input().split()))
	dp = [0] * m
	sum = 0
	for i in range(n):
		dp[mass[i] % m] += 1
	if m % 2 == 0:
		for j in range(1, m // 2):
			if dp[j] != 0 and dp[m - j] != 0:
				ma = max(dp[j], dp[m - j])
				mi = min(dp[j], dp[m - j])
				if ma == mi:
					sum += 1
				else:
					sum += ma - (mi + 1) + 1
			else:
				if dp[j] != 0:
					sum += dp[j]
				if dp[m - j] != 0:
					sum += dp[m - j]
		if dp[0] != 0:
			sum += 1
		if dp[m // 2] != 0:
			sum += 1
	else:
		for j in range(1, m // 2 + 1):
			if dp[j] != 0 and dp[m - j] != 0:
				ma = max(dp[j], dp[m - j])
				mi = min(dp[j], dp[m - j])
				if ma == mi:
					sum += 1
				else:
					sum += ma - (mi + 1) + 1
			else:
				if dp[j] != 0:
					sum += dp[j]
				if dp[m - j] != 0:
					sum += dp[m - j]
		if dp[0] != 0:
			sum += 1
	ans.append(sum)
for j in ans:
	print(j)


import collections
T = int(input())
for _ in range(T):
	buf = input()
	temp = buf.split(' ')
	(n, m) = (int(temp[0]), int(temp[1]))
	F = [0] * m
	buf = input()
	A = [int(x) for x in buf.split(' ')]
	for x in A:
		F[x % m] += 1
	ret = n
	if F[0] > 0:
		ret -= F[0] - 1
	for i in range(1, m):
		if i > m - i:
			break
		if F[i] == 0 or F[m - i] == 0:
			continue
		if i == m - i:
			ret -= F[i] - 1
			F[i] = 0
			break
		if F[i] == F[m - i]:
			ret -= F[i] + F[m - i] - 1
			(F[i], F[m - i]) = (0, 0)
		elif F[i] > F[m - i]:
			ret -= F[m - i] + F[m - i]
			(F[i], F[m - i]) = (0, 0)
		elif F[i] < F[m - i]:
			ret -= F[i] + F[i]
			(F[i], F[m - i]) = (0, 0)
	print(ret)


def mArrays(n, m, array):
	d = {}
	for x in array:
		if x % m in d:
			d[x % m] += 1
		else:
			d[x % m] = 1
	v = set()
	ans = 0
	for x in d:
		if x not in v:
			if m - x in d and m - x not in v:
				if abs(d[x] - d[m - x]) > 1:
					ans += abs(d[x] - d[m - x])
				else:
					ans += 1
			elif x == 0:
				ans += 1
			else:
				ans += d[x]
			v.add(x)
			v.add(m - x)
	return ans
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	print(mArrays(n, m, l))


import sys
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	db = [0] * m
	for i in map(int, sys.stdin.readline().split()):
		db[i % m] += 1
	res = 0
	if m == 1:
		res = 1
	elif m == 2:
		res += bool(db[0]) + bool(db[1])
	else:
		for i in range(1, (m + 1) // 2):
			if db[i] == db[m - i]:
				if db[i]:
					res += 1
			else:
				res += abs(db[i] - db[m - i])
		if m % 2:
			res += bool(db[0])
		else:
			res += bool(db[0]) + bool(db[m // 2])
	print(res)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
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')

class SegmentTree:

	def __init__(self, data, default=10 ** 10, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=10 ** 6, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(200001)]
pp = []

def SieveOfEratosthenes(n=200000):
	p = 2
	c = 0
	while p * p <= n:
		if prime[p] == True:
			c += 1
			pp.append(p)
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1

def binarySearch(arr, n, key):
	left = 0
	right = n - 1
	mid = 0
	res = 0
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] > key:
			right = mid - 1
		else:
			res = mid + 1
			left = mid + 1
	return res
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	d = defaultdict(int)
	for i in a:
		d[i % m] += 1
	res = 0
	if d[0] > 0:
		res = 1
	for i in range(1, m // 2 + 1):
		(x, y) = (d[i], d[m - i])
		mn = min(x, y)
		mx = max(x, y)
		k = 0
		if mn > 0:
			res += 1
			k = 1
		res += max(0, mx - mn - k)
	print(res)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	remainders = [0 for i in range(m)]
	for _ in arr:
		remainders[_ % m] += 1
	if remainders[0] > 0:
		ans = 1
	else:
		ans = 0
	if m % 2 == 0:
		if remainders[m // 2] > 0:
			ans += 1
		for _ in range(1, m // 2):
			if remainders[_] != 0 and remainders[_] == remainders[m - _]:
				ans += 1
			else:
				ans += abs(remainders[_] - remainders[m - _])
	else:
		for _ in range(1, 1 + m // 2):
			if remainders[_] != 0 and remainders[_] == remainders[m - _]:
				ans += 1
			else:
				ans += abs(remainders[_] - remainders[m - _])
	print(ans)


t = int(input())
for asasd in range(t):
	V = [int(i) for i in input().split()]
	n = V[0]
	m = V[1]
	num = [int(i) for i in input().split()]
	num.sort()
	cont = 0
	res = [0] * m
	for i in num:
		res[i % m] += 1
	for i in range(1, m):
		a = res[i]
		b = res[m - i]
		if max(a, b) > 0:
			if a == b:
				cont += 1
			else:
				cont += max([a, b]) - min([a, b])
	if m % 2 == 0:
		if res[int(m / 2)] > 0:
			cont += 1
	cont = cont / 2
	if res[0] > 0:
		cont += 1
	print(int(cont))


T = int(input())
frange = range
fprint = print
fint = int
finput = input
for i in frange(T):
	ans = 0
	(n, m) = map(fint, finput().split())
	arr = list(map(fint, finput().split()))
	b = [0] * m
	for i in range(n):
		arr[i] %= m
		b[arr[i] % m] += 1
	if b[0]:
		ans += 1
	for i in range(1, m):
		if b[i] != 0:
			l = b[m - i]
			if abs(l - b[i]) <= 1:
				ans += 1
			else:
				ans += abs(b[i] - l)
			b[m - i] = 0
	fprint(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	dic = {}
	for i in range(n):
		arr[i] = arr[i] % m
		if dic.get(arr[i], -1) == -1:
			dic[arr[i]] = 1
		else:
			dic[arr[i]] += 1
	c = 0
	for i in dic:
		if i == 0 or i == m - i:
			c += 1
			dic[i] = 0
		elif dic.get(m - i, -1) != -1:
			if dic[i] and dic[m - i]:
				(a, b) = (dic[i], dic[m - i])
				t = min(a, b)
				dic[i] -= t
				dic[m - i] -= t
				if dic[i]:
					dic[i] -= 1
				elif dic[m - i]:
					dic[m - i] -= 1
				c += 1
	for i in dic:
		c += dic[i]
	print(c)


def MArrays(a, m):
	s = dict()
	n = 0
	for i in range(len(a)):
		if a[i] % m in s.keys():
			s[a[i] % m] += 1
		else:
			s[a[i] % m] = 1
	if 0 in s.keys():
		n += 1
		s.pop(0)
	if len(s) != 0:
		for i in range(1, m // 2 + 1):
			if i == m / 2 and i in s.keys():
				n += 1
				s.pop(i)
			elif i in s.keys() and m - i in s.keys():
				if abs(s[m - i] - s[i]) <= 1:
					n += 1
					s.pop(i)
					s.pop(m - i)
				else:
					n += abs(s[m - i] - s[i])
					s.pop(i)
					s.pop(m - i)
	if len(s) != 0:
		n = sum(list(s.values()), n)
	return n
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	print(MArrays(a, m))


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	store = [0 for i in range(k)]
	if n == 1 or k == 1:
		print(1)
		continue
	for i in a:
		store[i % k] += 1
	c = 0
	if store[0] > 0:
		c += 1
	if k % 2 == 0 and store[k // 2] > 0:
		c += 1
	if k % 2 == 0:
		r = k // 2
	else:
		r = k // 2 + 1
	for i in range(1, r):
		if store[i] or store[k - i]:
			x = abs(store[i] - store[k - i])
			if x <= 1:
				c += 1
			else:
				c += x
	print(c)


t = int(input())
for i in range(t):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	mod = []
	for j in range(m):
		mod.append(0)
	s = list(input().split())
	for j in s:
		mod[int(j) % m] += 1
	if mod[0] != 0:
		result = 1
	else:
		result = 0
	for j in range(1, m // 2 + 1):
		if mod[j] != 0:
			if mod[j] == mod[m - j]:
				result += 1
			elif mod[m - j] != 0:
				result = result + 1 + max(mod[j], mod[m - j]) - min(mod[j], mod[m - j]) - 1
			else:
				result += mod[j]
		else:
			result += mod[m - j]
	print(result)


t = int(input())
while t > 0:
	t -= 1
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	for i in range(len(a)):
		if a[i] % m in d:
			d[a[i] % m] += 1
		else:
			d[a[i] % m] = 1
	ans = 0
	if 0 in d:
		ans += 1
		del d[0]
	for i in d:
		x = m - i
		if d[i] == -1:
			continue
		if x == i:
			ans += 1
			d[i] = -1
		elif x in d and d[x] != -1:
			if x == i:
				ans += 1
				d[x] = -1
			elif d[x] < d[i]:
				d[i] -= d[x]
				d[i] -= 1
				d[x] = -1
				ans += 1
				if d[i] > 0:
					ans += d[i]
				d[i] = -1
			else:
				d[x] -= d[i]
				d[x] -= 1
				d[i] = -1
				ans += 1
				if d[x] > 0:
					ans += d[x]
				d[x] = -1
		else:
			ans += d[i]
			d[i] = -1
	print(ans)


import math as m
i = int(input())
inp = []
for a in range(0, i):
	inp += [[[int(x) for x in input().split()], [int(x) for x in input().split()]]]
for i in inp:
	[n, m] = i[0]
	arr = [x % m for x in i[1]]
	d = {}
	even = m % 2 == 0
	l = m // 2
	for x in arr:
		if x > l:
			x_c = m - x
			if x_c in d:
				d[x_c][1] = d[x_c][1] + 1
			else:
				d[x_c] = [0, 1]
		elif x in d:
			d[x][0] = d[x][0] + 1
		else:
			d[x] = [1, 0]
	c = 0
	for k in d:
		if k == 0:
			c += 1
		elif k == l and even:
			c += 1
		else:
			c += max(1, abs(d[k][0] - d[k][1]))
	print(c)


import os, sys, math
from io import BytesIO, IOBase
read = lambda : map(int, input().split(' '))

def main():
	for _ in range(int(input())):
		(n, k) = read()
		arr = list(read())
		if n == 1:
			print(1)
		elif k == 1:
			print(1)
		else:
			mod = [0] * k
			for i in range(n):
				mod[arr[i] % k] += 1
			x = max(mod[0] - 1, 0)
			l = int(k / 2)
			for i in range(1, l):
				if mod[i] != 0 and mod[k - i] != 0:
					x += min(2 * mod[i] + 1, 2 * mod[k - i] + 1, mod[i] + mod[k - i]) - 1
			if k % 2 == 0:
				x += max(mod[l] - 1, 0)
			elif k % 2 != 0:
				if mod[l] != 0 and mod[l + 1] != 0:
					x += min(2 * mod[l] + 1, 2 * mod[l + 1] + 1, mod[l + 1] + mod[l]) - 1
			print(n - x)
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 sys import stdin, stdout
from collections import Counter, OrderedDict
import math
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))

def chars():
	s = cin()
	return list(s[:len(s) - 1])

def pl(a):
	for val in a:
		cout(str(val) + ' ')
	cout('\n')
(t,) = mp()
for _ in range(t):
	(n, m) = mp()
	a = mp()
	l = [0] * m
	cnt = 0
	for i in range(n):
		l[a[i] % m] += 1
	if l[0] > 0:
		cnt += 1
	for i in range(1, m // 2 + 1):
		x = l[i]
		y = l[m - i]
		if x == 0 and y == 0:
			cnt += 0
		else:
			diff = max(x, y) - min(x, y)
			cnt += 1 + max(0, diff - 1)
	cout(str(cnt) + '\n')


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	rem = [0] * m
	for j in a:
		remi = j % m
		rem[remi] += 1
	ans = 0
	if rem[0]:
		ans += 1
	for k in range(1, m // 2 + 1):
		if rem[k] == rem[m - k] and rem[k] != 0:
			ans += 1
			continue
		p = min(rem[k], rem[m - k])
		if not p:
			ans += abs(rem[k] - rem[m - k])
			continue
		ans += 1
		extra = abs(rem[k] - rem[m - k]) - 1
		ans += extra
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
while t:
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = 0
	freq = {}
	for i in range(m):
		freq[i] = 0
	for i in a:
		freq[i % m] += 1
	for i in range(m // 2 + 1):
		if i == 0:
			if freq[0] == 0:
				ans += 0
			else:
				ans += 1
			continue
		if freq[i] == freq[m - i]:
			if freq[i] != 0:
				ans += 1
		else:
			ans += abs(freq[i] - freq[m - i])
	print(ans)
	t -= 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 main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

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

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l

def sq(a, target, arr=[]):
	s = sum(arr)
	if s == target:
		return arr
	if s >= target:
		return
	for i in range(len(a)):
		n = a[i]
		remaining = a[i + 1:]
		ans = sq(remaining, target, arr + [n])
		if ans:
			return ans

def SieveOfEratosthenes(n):
	cnt = 0
	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
	for p in range(2, n + 1):
		if prime[p]:
			cnt += 1
	return cnt

def nCr(n, r):
	f = math.factorial
	return f(n) // f(r) // f(n - r)
mod = int(1000000000.0) + 7

def ssinp():
	return input()

def iinp():
	return int(input())

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

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

def p(xyz):
	print(xyz)

def p2(a, b):
	print(a, b)
import math
from collections import OrderedDict
for __ in range(iinp()):
	(n, m) = nninp()
	a = llinp()
	rem = [0] * m
	ans = 0
	for c in a:
		rem[c % m] += 1
	if m % 2 == 1:
		if rem[0] > 0:
			ans += 1
		for i in range(1, math.ceil(m / 2)):
			a = rem[i]
			b = rem[m - i]
			if a > 0 and b > 0:
				if a != b:
					ans += max(a, b) - min(a, b)
				else:
					ans += 1
			else:
				ans = ans + max(a, b)
	else:
		if rem[0] > 0:
			ans += 1
		if rem[m // 2] > 0:
			ans += 1
		for i in range(1, math.ceil(m / 2)):
			a = rem[i]
			b = rem[m - i]
			if a > 0 and b > 0:
				if a != b:
					ans += max(a, b) - min(a, b)
				else:
					ans += 1
			else:
				ans = ans + max(a, b)
	p(ans)


import collections
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	an = [x % m for x in a]
	dn = collections.Counter(an)
	result = 0
	keys = list(dn.keys())
	for k in keys:
		if dn[k] == 0:
			continue
		if k == 0:
			result += 1
			dn[k] = 0
		elif k * 2 == m:
			result += 1
			dn[k] = 0
		else:
			result += 1
			s = min(dn[k], dn[m - k])
			dn[k] = max(0, dn[k] - s - 1)
			dn[m - k] = max(0, dn[m - k] - s - 1)
	for k in keys:
		result += dn[k]
	print(result)


import sys
input = sys.stdin.readline
from collections import Counter
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	c = Counter()
	for i in a:
		c[i % m] += 1
	cnt = 0
	s = set()
	for i in c:
		if i == 0:
			cnt += 1
			continue
		if i in s:
			continue
		cnt += max(1, abs(c[i] - c[m - i]))
		s.add(i)
		s.add(m - i)
	print(cnt)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	mod = [0] * m
	for i in a:
		mod[i % m] += 1
	ans = 0
	if mod[0] != 0:
		ans += 1
	for i in range(1, m):
		if m - i < i:
			break
		if i * 2 == m:
			if mod[i] != 0:
				ans += 1
		elif mod[i] == 0 and mod[m - i] == 0:
			continue
		elif mod[i] == 0 or mod[m - i] == 0:
			ans += mod[i] + mod[m - i]
		else:
			ans += 1
			if mod[i] != mod[m - i]:
				ans += abs(mod[m - i] - mod[i]) - 1
	print(ans)


tim = int(input())
while tim > 0:
	tim -= 1
	(n, m) = map(int, input().split())
	ar = list(map(int, input().split()))
	cnt = [0 for i in range(m)]
	for i in range(n):
		ar[i] = ar[i] % m
		cnt[ar[i]] += 1
	ans = 0
	if cnt[0] != 0:
		ans += 1
	if m % 2 == 0:
		if cnt[m // 2] != 0:
			ans += 1
	for i in range(1, (m + 1) // 2):
		a = cnt[i]
		b = cnt[m - i]
		if a > b:
			(a, b) = (b, a)
		if b == 0:
			continue
		ans += 1 + max(0, b - a - 1)
	print(ans)


from sys import *
from itertools import accumulate
input = lambda : stdin.readline()
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)
for _ in range(int(input())):
	(n, m) = get_int()
	arr = int_arr()
	lst = [0] * m
	for i in arr:
		val = i % m
		lst[val] += 1
	ct = 0
	for i in range(m // 2 + 1):
		val1 = (m - i) % m
		if lst[val1] + lst[i] > 0:
			ct += max(1, abs(lst[val1] - lst[i]))
	print(ct)


import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	L = [*map(int, input().split())]
	if n == 1:
		print(1)
		continue
	mul = False
	ans = n
	dic = {}
	for el in L:
		ths = el % m
		if not ths:
			if not mul:
				mul = True
				continue
			ans -= 1
			continue
		if ths in dic:
			dic[ths] += 1
		else:
			dic[ths] = 1
	chk = {}
	half = m // 2
	if m % 2:
		half += 1
	if not m % 2:
		if half in dic:
			ans -= dic[half] - 1
	A = sorted(dic.keys())
	for el in A:
		if el >= half:
			break
		if m - el in dic:
			(a, b) = (dic[el], dic[m - el])
			if a == b:
				ans -= 2 * a - 1
				continue
			if a + b == 2:
				ans -= 1
				continue
			if a > b:
				(a, b) = (b, a)
			ans -= 2 * a
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	dico = {}
	for x in a:
		if x % m in dico:
			dico[x % m] += 1
		else:
			dico.update({x % m: 1})
	r = n
	for x in dico.keys():
		if 0 < 2 * x < m:
			y = m - x
			dicox = dico[x]
			dicoy = 0
			if y in dico:
				dicoy = dico[y]
			score = 2 * min(dicox, dicoy)
			if dicox == dicoy:
				score -= 1
			r -= score
	if m % 2 == 0 and m // 2 in dico:
		dici = dico[m // 2]
		r -= dici
		r += 1
	if 0 in dico:
		dici = dico[0]
		r -= dici
		r += 1
	print(r)


for t in range(int(input())):
	(n, k) = list(map(int, input().split(' ')))
	a = list(map(int, input().split(' ')))
	d = [0] * k
	for i in range(0, len(a)):
		d[a[i] % k] += 1
	op = 0
	if d[0] > 0:
		op += 1
	for i in range(1, k // 2 + 1):
		if d[i] == 0 or d[k - i] == 0:
			op += d[i] + d[k - i]
		elif abs(d[i] - d[k - i]) <= 1:
			op += 1
		else:
			op += abs(d[i] - d[k - i])
	print(op)


import sys
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	A = [a % m for a in A]
	X = [0] * m
	for a in A:
		X[a] += 1
	ans = 0
	for i in range(m // 2 + 1):
		if i == 0:
			if X[i]:
				ans += 1
		elif m % 2 == 0 and i == m // 2:
			if X[m // 2]:
				ans += 1
		else:
			j = m - i
			(maxv, minv) = (max(X[i], X[j]), min(X[i], X[j]))
			if maxv == 0:
				continue
			if maxv == minv:
				ans += 1
			elif maxv == minv + 1:
				ans += 1
			else:
				ans += maxv - (minv + 1) + 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	li = list(map(int, input().split()))
	lim = [0] * m
	for ele in li:
		k = ele % m
		lim[k] = lim[k] + 1
	ans = 0
	if m % 2 == 0:
		p = m // 2
	else:
		p = (m + 1) // 2
	for i in range(1, p):
		if lim[i] == 0 or lim[m - i] == 0:
			ans = ans + lim[i] + lim[m - i]
		elif lim[i] == lim[m - i]:
			ans = ans + 1
		else:
			ans = ans + abs(lim[i] - lim[m - i])
	if lim[0] != 0:
		ans = ans + 1
	if m % 2 == 0:
		if lim[m // 2] != 0 and m != 1:
			ans = ans + 1
	print(ans)


t = int(input())
for _ in range(0, t):
	(n, m) = map(int, input().split(' '))
	d = [0] * m
	q = list(map(int, input().split(' ')))
	for i in q:
		d[i % m] += 1
	c = 0
	if d[0] > 0:
		c += 1
	for x in range(1, (m + 1) // 2):
		if d[x] > 0 or d[m - x] > 0:
			c += max(1, abs(d[m - x] - d[x]))
	if d[m // 2] != 0 and m % 2 == 0:
		c += 1
	print(c)


from sys import stdin, stdout
input = stdin.readline
import math
from collections import Counter
import bisect

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

def tl():
	return list(map(int, input().split(' ')))
big = 0
for _ in range(int(input())):
	big += 1
	(n, m) = ti()
	a = tl()
	temp = [i % m for i in a]
	counts = [0 for i in range(m)]
	ans = 0
	for i in range(n):
		counts[temp[i]] += 1
	if counts[0]:
		ans += 1
	if m % 2 == 0 and counts[m // 2]:
		ans = ans + 1
	for i in range(1, (m + 1) // 2):
		if counts[i] != 0 or counts[m - i] != 0:
			ans = ans + max(abs(counts[i] - counts[m - i]) - 1, 0) + 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	d = {}
	for i in range(m):
		d[i] = 0
	for i in range(n):
		d[arr[i] % m] += 1
	if len(arr) == 1:
		print(1)
	else:
		if d[0] > 0:
			ans = 1
		else:
			ans = 0
		for i in range(1, m // 2 + 1):
			if d[i] == d[m - i]:
				if d[i] > 0:
					ans += 1
			elif d[i] > d[m - i]:
				if d[m - i] == 0:
					ans += d[i]
				else:
					ans += 1
					a = d[i] - (d[m - i] + 1)
					ans += a
			elif d[i] == 0:
				ans += d[m - i]
			else:
				ans += 1
				a = d[m - i] - (d[i] + 1)
				ans += a
		print(ans)


def ass(a, b):
	print(f'Assertion error: {a} != {b}' if a != b else 'OK')

def number():
	return int(input())

def numbers():
	return [int(item) for item in input().split()]

def f(m, arr):
	res = [0 for i in range(m)]
	for item in arr:
		res[item % m] += 1
	total = 0
	if m % 2 == 0:
		if res[0] > 0:
			total += 1
		if res[m // 2] > 0:
			total += 1
		for i in range(1, m // 2):
			j = m - i
			diff = abs(res[i] - res[j])
			if diff == 0:
				if res[i] != 0:
					total += 1
			elif diff <= 1:
				total += 1
			else:
				total += diff
		return total
	else:
		if res[0] > 0:
			total += 1
		for i in range(1, (m + 1) // 2):
			j = m - i
			diff = abs(res[i] - res[j])
			if diff == 0:
				if res[i] > 0:
					total += 1
			else:
				total += diff
		return total
for i in range(number()):
	(n, m) = numbers()
	print(f(m, numbers()))


import math

def solve():
	(n, m) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	rem = {}
	for a in arr:
		r = a % m
		rem[r] = 1 if r not in rem else rem[r] + 1
	ans = 0
	for (a, cnt) in rem.items():
		if a == 0:
			ans += 1
		elif a == m / 2:
			ans += 1
		elif a < m / 2 or m - a not in rem:
			y = rem[m - a] if m - a in rem else 0
			diff = abs(cnt - y)
			if diff <= 1:
				ans += 1
			else:
				ans += diff
	return ans
tc = int(input())
for _ in range(tc):
	print(solve())


for tt in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	lm = [0 for i in range(m)]
	for i in l:
		lm[i % m] += 1
	cnt = 0
	if lm[0] >= 1:
		cnt += 1
	if m % 2 == 0 and lm[m // 2] >= 1:
		cnt += 1
	for i in range(1, m // 2 + m % 2):
		ma = max(lm[m - i], lm[i])
		mi = min(lm[m - i], lm[i])
		jo = 0
		if ma > 0:
			jo = 1
		cnt += max(ma - mi, jo)
	print(cnt)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	mod = [0] * m
	for i in range(n):
		mod[A[i] % m] += 1
	ans = 0
	if mod[0] != 0:
		ans += 1
	for i in range(1, m // 2 + 1):
		_max = max(mod[i], mod[m - i])
		_min = min(mod[i], mod[m - i])
		if _max == 0 and _min == 0:
			continue
		elif _max - _min <= 1:
			ans += 1
		else:
			ans += _max - (_min + 1) + 1
	print(ans)


def m_arrays(arr, k):
	modulo = {}
	seen = set()
	for num in arr:
		modulo[num % k] = modulo.get(num % k, 0) + 1
	ans = 0
	for c in modulo:
		if k - c not in seen:
			if k - c in modulo:
				first = modulo[c]
				second = modulo[k - c]
				ans += max(abs(first - second) - 1, 0) + 1
			elif c == 0:
				ans += 1
			else:
				ans += modulo[c]
		seen.add(c)
	return ans
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(m_arrays(arr, k))


def solve():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	x = [0] * m
	for i in range(n):
		x[a[i] % m] += 1
	c = 0
	if x[0] != 0:
		c += 1
	for i in range(1, m // 2 + 1):
		if x[i] != x[m - i]:
			z = min(x[i], x[m - i]) + 1
			c += 1 + max(x[i], x[m - i]) - z
		elif x[i] != 0:
			c += 1
	print(c)

def main():
	for ii in range(int(input())):
		solve()
main()


from sys import stdin, stdout
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import *
input = stdin.readline
prin = stdout.write
from random import sample
from collections import Counter, deque
from math import sqrt, ceil, log2, gcd
mod = 10 ** 9 + 7

def f(arr, i, j, d, dist):
	if i == j:
		return
	nn = max(arr[i:j])
	for tl in range(i, j):
		if arr[tl] == nn:
			dist[tl] = d
			f(arr, i, tl, d + 1, dist)
			f(arr, tl + 1, j, d + 1, dist)

def ps(n):
	cp = 0
	lk = 0
	arr = {}
	while n % 2 == 0:
		n = n // 2
		lk += 1
	arr[2] = lk
	for ps in range(3, ceil(sqrt(n)) + 1, 2):
		lk = 0
		while n % ps == 0:
			n = n // ps
			arr.append(n)
			arr.append(ps ** (lk + 1))
			lk += 1
		arr[ps] = lk
	if n != 1:
		lk += 1
		arr[n] = lk
	return arr

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

def factorials(n, r):
	slr = n
	dpr = r
	qlr = 1
	qs = 1
	mod = 10 ** 9 + 7
	for ip in range(n - r + 1, n + 1):
		qlr = qlr * ip % mod
	for ij in range(1, r + 1):
		qs = qs * ij % mod
	ans = qlr * modInverse(qs) % mod
	return ans

def modInverse(b):
	qr = 10 ** 9 + 7
	return pow(b, qr - 2, qr)
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def power(arr):
	listrep = arr
	subsets = []
	for i in range(2 ** len(listrep)):
		subset = []
		for k in range(len(listrep)):
			if i & 1 << k:
				subset.append(listrep[k])
		subsets.append(subset)
	return subsets

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

def dis(xa, ya, xb, yb):
	return sqrt((xa - xb) ** 2 + (ya - yb) ** 2)

def ii():
	return int(input())

def ilist():
	return [int(x) for x in input().strip().split()]

def out(array: list) -> str:
	array = [str(x) for x in array]
	return ' '.join(array)

def islist():
	return list(map(str, input().split().rstrip()))

def outfast(arr: list) -> str:
	ss = ''
	for ip in arr:
		ss += str(ip) + ' '
	return prin(ss)
t = int(input())
for jj in range(t):
	(n, m) = ilist()
	arr = ilist()
	ss = {}
	for i in range(n):
		if arr[i] % m in ss:
			ss[arr[i] % m] += 1
		else:
			ss[arr[i] % m] = 1
	jj = set()
	co = 0
	for jp in ss:
		tt = m - jp
		if jp not in jj and tt != jp and (jp != 0):
			kl = 0
			if tt in ss:
				kl = ss[tt]
			(aa, bb) = (max(kl, ss[jp]), min(kl, ss[jp]))
			if aa == bb:
				co += 1
			else:
				co += 1 + (aa - bb - 1)
			jj.add(tt)
			jj.add(jp)
		elif jp == 0 or 2 * jp == m:
			co += 1
			jj.add(jp)
	print(co)


from sys import stdin, stdout
from collections import Counter
nmbr = lambda : int(input())
lst = lambda : list(map(int, input().split()))
for _ in range(nmbr()):
	(n, k) = lst()
	a = list(map(lambda x: int(x) % k, input().split()))
	if n == 1:
		print(1)
		continue
	d = Counter(a)
	ans = 0
	vis = set()
	for v1 in range(k):
		v2 = k - v1 if v1 != 0 else 0
		if v1 in vis or v2 in vis:
			continue
		vis.add(v1)
		vis.add(v2)
		if d[v1] == d[v2] == 0:
			continue
		if v1 == v2 and d[v1]:
			ans += 1
			continue
		if d[v1] == d[v2]:
			ans += 1
		elif d[v1] > 0 and d[v2] == 0:
			ans += d[v1]
		elif d[v2] > 0 and d[v1] == 0:
			ans += d[v2]
		else:
			(mn, mx) = (d[v1], d[v2])
			if mn > mx:
				(mn, mx) = (mx, mn)
			left = mx - mn - 1
			ans += 1 + left
	print(ans)


import sys
input = sys.stdin.readline
for f in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	res = [0] * m
	for x in l:
		res[x % m] += 1
	res.append(res[0])
	ans = 0
	for i in range(m + 1):
		(a, b) = (res[i], res[-i - 1])
		(a, b) = (max(a, b), min(a, b))
		r = 0
		if a:
			r += 1
		if a - b > 1:
			r += a - b - 1
		if 2 * i == m:
			r *= 2
		ans += r
	print(ans // 2)


from collections import Counter
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = Counter(map(lambda x: int(x) % m, input().split()))
	res = 0
	for i in range(m // 2 + 1):
		if i == 0 and arr[0] != 0:
			res += 1
		else:
			(x, y) = sorted([arr[i], arr[m - i]])
			if y == 0:
				continue
			if x == 0:
				res += y
				continue
			res += 1
			if x == y:
				continue
			else:
				res += y - x - 1
	print(res)


def solve(arr, m):
	rem = [0 for i in range(m)]
	for x in arr:
		temp = x % m
		rem[temp] += 1
	count = 0
	if len(arr) == 1:
		return 1
	for i in range(m // 2 + 1):
		if i == 0 and rem[0] != 0:
			count += 1
		elif i != 0:
			x = rem[i]
			y = rem[m - i]
			(x, y) = (max(x, y), min(x, y))
			if x == y and x != 0:
				count += 1
			elif x != y:
				z = y + 1
				count += 1
				x = x - z
				count += x
	return count
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(solve(arr, m))


from io import BytesIO, IOBase
import sys, os
inpl = lambda : list(map(int, input().split()))
inpm = lambda : map(int, input().split())
inpi = lambda : int(input())
inp = lambda : input()
(rev, ra, l) = (reversed, range, len)
P = print
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')
from bisect import bisect_left as bl
from bisect import bisect_right as br
import sys, operator, math, operator
from collections import Counter
tc = inpi()
while tc:
	(n, m) = inpm()
	omap = {}
	li = inpl()
	for i in ra(n):
		if li[i] % m in omap:
			omap[li[i] % m] += 1
		else:
			omap[li[i] % m] = 1
	ans = 0
	for (k, v) in omap.items():
		if v == 0:
			continue
		if k == 0:
			ans += 1
		elif m - k in omap:
			if k == m / 2:
				ans += 1
			elif v > omap[m - k]:
				omap[k] = v - omap[m - k] - 1
				ans += 1
				ans += omap[k]
				omap[m - k] = 0
			elif v == omap[m - k]:
				ans += 1
				omap[m - k] = 0
			else:
				ans += 1
				omap[m - k] = omap[m - k] - v - 1
				omap[k] = 0
		else:
			ans += v
	P(ans)
	tc -= 1


for i in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	info = {}
	ans = 0
	for i in range(n):
		arr[i] = arr[i] % m
		if not arr[i]:
			ans = 1
			continue
		info[arr[i]] = info.get(arr[i], 0) + 1
	for (key, value) in info.items():
		if key == m / 2 or (info.get(m - key) and key > m / 2):
			continue
		dif = abs(value - info.get(m - key, 0))
		if dif == 0:
			dif += 1
		ans += dif
	if info.get(m / 2):
		ans += 1
	print(ans)


from collections import defaultdict, Counter
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr = [el % m for el in arr]
	d = Counter(arr)
	ans = 0
	if d[0] > 0:
		ans += 1
	if m % 2 == 0 and d[m // 2] > 0:
		ans += 1
	for i in range(1, (m + 1) // 2):
		if d[i] > 0 or d[m - i] > 0:
			ans += 1
			if abs(d[i] - d[m - i]) > 1:
				ans += abs(d[i] - d[m - i]) - 1
	print(ans)


from collections import Counter
t = int(input())
for j in range(0, t):
	(n, m) = map(int, input().split())
	a = [int(x) % m for x in input().split()]
	d = Counter(a)
	ans = 0
	for i in set(a):
		if d[i] < 0:
			continue
		x = (m - i) % m
		v = min(d[x], d[i]) + (d[x] != d[i])
		ans += max(d[x], d[i]) - v + 1
		d[x] = -1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	mod = [0] * m
	for a in arr:
		mod[a % m] += 1
	count = 0
	if mod[0] != 0:
		count = 1
	for i in range(1, m):
		if mod[i] != None:
			if mod[m - i] == 0:
				count += mod[i]
			elif abs(mod[i] - mod[m - i]) <= 1:
				count += 1
			else:
				count += abs(mod[i] - mod[m - i])
			mod[m - i] = None
	print(count)


from collections import Counter

def solve(m, l):
	l = map(lambda x: x % m, l)
	c = Counter(l)
	res = 0
	if m % 2 == 0:
		for i in range(1, m // 2):
			sm = c[i]
			lg = c[m - i]
			if sm == lg and sm != 0:
				res += 1
			elif abs(sm - lg) == 1:
				res += 1
			elif sm == 0 and lg == 0:
				pass
			elif sm == 0 or lg == 0:
				res += max(sm, lg)
			else:
				res += 1
				res += max(sm, lg) - (min(sm, lg) + 1)
		if c[m // 2] > 0:
			res += 1
	else:
		for i in range(1, m // 2 + 1):
			sm = c[i]
			lg = c[m - i]
			if sm == lg and sm != 0:
				res += 1
			elif abs(sm - lg) == 1:
				res += 1
			elif sm == 0 and lg == 0:
				pass
			elif sm == 0 or lg == 0:
				res += max(sm, lg)
			else:
				res += 1
				res += max(sm, lg) - (min(sm, lg) + 1)
	if c[0] > 0:
		res += 1
	return res
cases = int(input())
for ii in range(cases):
	(_, m) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	print(solve(m, l))


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


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(inp())
for _ in range(t):
	(n, m) = multi()
	a = lis()
	hashy = {}
	for i in a:
		if i % m not in hashy:
			hashy[i % m] = 1
		else:
			hashy[i % m] += 1
	ans = 0
	if 0 in hashy:
		ans += 1
	for i in range(1, m // 2 + 1):
		if m - i in hashy and i in hashy:
			ans += 1 + max(0, max(hashy[i], hashy[m - i]) - (min(hashy[i], hashy[m - i]) + 1))
		else:
			if i in hashy:
				ans += hashy[i]
			if m - i in hashy:
				ans += hashy[m - i]
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = list(map(int, input().split()))
	r = [0] * m
	for i in s:
		r[i % m] += 1
	ans = 0
	if r[0]:
		ans += 1
	if not m % 2 and r[m // 2]:
		ans += 1
	for i in range(1, (m + 1) // 2):
		if r[i] or r[m - i]:
			ans += 1
			if abs(r[i] - r[m - i]) > 1:
				ans += abs(r[i] - r[m - i]) - 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [0] * m
	for i in input().split():
		a[int(i) % m] += 1
	ans = a[0] > 0
	a[0] = 0
	if m % 2 == 0:
		ans += a[m // 2] > 0
		a[m // 2] = 0
	for i in range(1, m):
		while a[i] > a[m - i] + 1:
			ans += 1
			a[i] -= 1
		if a[i] > 0 and -2 < a[i] - a[m - i] < 2:
			ans += 1
			a[i] = 0
			a[m - i] = 0
	ans += sum(a)
	print(ans)


def solve():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	if m == 1:
		return 1
	modvals = [0] * m
	for i in a:
		modvals[i % m] += 1
	ans = 1 if modvals[0] > 0 else 0
	rlim = (m + 1) // 2
	for i in range(1, rlim):
		mx = max(modvals[i], modvals[m - i])
		if mx == 0:
			continue
		mi = modvals[i] + modvals[m - i] - mx
		if mi > 0:
			ans += 1
			ans += max(0, modvals[m - i] + modvals[i] - 2 * mi - 1)
		else:
			ans += mx
	if m & 1 == 0 and modvals[rlim] > 0:
		ans += 1
	return ans
for _ in range(int(input())):
	print(solve())


def func(arr, n, m):
	arr = [i % m for i in arr]
	am = {i: 0 for i in range(m)}
	for i in arr:
		am[i] += 1
	c = 0
	if am[0] > 0:
		c += 1
	if m % 2 == 0 and am[m // 2] > 0:
		c += 1
	ub = m // 2 if m % 2 == 0 else m // 2 + 1
	for i in range(1, ub):
		(mi, ma) = (min(am[i], am[m - i]), max(am[i], am[m - i]))
		if mi == 0:
			c += ma
		elif ma - mi > 1:
			c += ma - mi
		else:
			c += 1
	print(c)
t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	func(arr, n, m)


from pprint import pprint
import sys
input = sys.stdin.readline

def do():
	(n, m) = map(int, input().split())
	dat = list(map(lambda x: int(x) % m, input().split()))
	buf = [0] * m
	for x in dat:
		buf[x] += 1
	res = 0
	if buf[0] > 0:
		res += 1
	if m % 2 == 0:
		for i in range(1, m // 2):
			(l, r) = (buf[i], buf[m - i])
			(l, r) = (min(l, r), max(l, r))
			if l == 0 and r == 0:
				continue
			res += 1
			if l == r:
				continue
			if l + 1 == r:
				continue
			res += r - (l + 1)
		center = buf[m // 2]
		if center != 0:
			res += 1
	else:
		for i in range(1, (m + 1) // 2):
			(l, r) = (buf[i], buf[m - i])
			(l, r) = (min(l, r), max(l, r))
			if l == 0 and r == 0:
				continue
			res += 1
			if l == r:
				continue
			if l + 1 == r:
				continue
			res += r - (l + 1)
	print(res)
q = int(input())
for _ in range(q):
	do()


from collections import Counter

def _i():
	return int(input())

def _il():
	return [int(x) for x in input().split()]

def _iil():
	n = _i()
	a = _il()
	assert n == len(a)
	return a

def solve(n, m, a):
	c = Counter([x % m for x in a])
	r = 0
	for (k, v) in c.items():
		if k > m - k and c[m - k] > 0:
			continue
		r += 1
		if k > 0 and 2 * k != m:
			w = c[m - k]
			(v, w) = (min(v, w), max(v, w))
			if w > v:
				r += w - v - 1
	return r
for _ in range(int(input())):
	(n, m) = _il()
	a = _il()
	print(solve(n, m, a))


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().rstrip().split()))
	arr = list(map(int, input().rstrip().split()))
	d = [0] * m
	for i in range(n):
		d[arr[i] % m] += 1
	count = 0
	if d[0] != 0:
		count += 1
	i = 1
	j = m - 1
	while j >= i:
		if d[i] == 0 and d[j]:
			count += d[j]
		elif d[j] == 0 and d[i]:
			count += d[i]
		elif d[j] == 0 and d[i] == 0:
			i += 1
			j -= 1
			continue
		elif i == j:
			count += 1
		elif abs(d[j] - d[i]) <= 1:
			count += 1
		else:
			mn = min(d[i], d[j])
			mx = max(d[i], d[j])
			count += mx - (mn + 1) + 1
		i += 1
		j -= 1
	print(count)


from itertools import permutations as perm
from fractions import Fraction
from collections import *
from sys import stdin
from bisect import *
from heapq import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(t,) = gil()
fi = []
for _ in range(t):
	(n, m) = gil()
	a = gil()
	for i in range(n):
		a[i] %= m
	b = Counter(a)
	ans = 1 if 0 in b else 0
	for i in range(1, m):
		(l, r) = (0, 0)
		if i in b:
			l = b[i]
			del b[i]
		if m - i in b:
			r = b[m - i]
			del b[m - i]
		if i == m - i:
			if l:
				ans += 1
		elif l and r:
			(mi, ma) = (min(l, r), max(l, r))
			ma = max(0, ma - mi - 1)
			if mi:
				ans += 1
			ans += ma
		else:
			ans += l + r
	fi.append(str(ans))
print('\n'.join(fi))


def d(a, n):
	l = [0] * n
	for i in range(len(a)):
		r = a[i] % n
		l[r] += 1
	if l[0] == 0:
		c = 0
	else:
		c = 1
	for i in range(1, n // 2 + 1):
		if i == n - i:
			if l[i] != 0:
				c += 1
			l[i] == 0
		elif l[i] > l[n - i]:
			l[i] -= l[n - i] + 1
			l[n - i] = 0
			c += 1
			c += l[i]
			l[i] = 0
		elif l[i] == l[n - i]:
			if l[i] != 0:
				c += 1
			l[i] == 0
			l[n - i] = 0
		else:
			l[n - i] -= l[i] + 1
			l[i] = 0
			c += 1
			c += l[n - i]
			l[n - i] = 0
	return c
t = int(input())
l = []
for i in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = d(a, m)
	l.append(s)
for y in l:
	print(y)


num_cases = int(input())
nums = []
for _ in range(num_cases):
	(n, m) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	num_arrs = 0
	mods = [0] * m
	for i in a:
		mods[i % m] += 1
	num_arrs = num_arrs + 1 if mods[0] > 0 else num_arrs
	mods[0] = 0
	for i in range(m // 2):
		a_start = mods[i + 1]
		a_end = mods[m - i - 1]
		if a_start != 0 and a_end != 0:
			if mods[i + 1] > a_end:
				mods[i + 1] -= mods[m - i - 1] + 1
				num_arrs += 1
				mods[m - i - 1] = 0
			elif mods[m - i - 1] > mods[i + 1]:
				mods[m - i - 1] -= mods[i + 1] + 1
				num_arrs += 1
				mods[i + 1] = 0
			else:
				mods[m - i - 1] = 0
				mods[i + 1] = 0
				num_arrs += 1
	num_arrs += sum(mods)
	nums.append(num_arrs)
for i in nums:
	print(i)


def process(A, m):
	d = {}
	for x in A:
		x2 = x % m
		if x2 not in d:
			d[x2] = 0
		d[x2] += 1
	answer = 0
	for x in d:
		if x == 0 or 2 * x == m:
			answer += 1
		elif m - x in d:
			if x < m - x:
				v1 = d[x]
				v2 = d[m - x]
				(v1, v2) = (min(v1, v2), max(v1, v2))
				if v1 == v2 or v1 + 1 == v2:
					answer += 1
				else:
					answer += 1
					answer += v2 - v1 - 1
		else:
			answer += d[x]
	return answer
t = int(input())
for i in range(t):
	(n, m) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	print(process(A, m))


for pratyush in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	(f, c) = ([], 0)
	for i in range(m):
		f.append(0)
	for i in range(n):
		f[a[i] % m] += 1
	for i in range(m // 2 + 1):
		if f[i] > 0:
			if i == 0 or (m % 2 == 0 and i == m / 2):
				c += 1
			else:
				x = max(f[i], f[m - i]) - min(f[i], f[m - i])
				if x <= 1:
					c += 1
				else:
					c += 1 + (x - 1)
		elif i != 0 and f[i] == 0 and (f[m - i] > 0):
			c += f[m - i]
	print(c)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	mod = {}
	ans = 0
	for x in arr:
		if x % m == 0:
			ans = 1
		else:
			try:
				mod[x % m] += 1
			except:
				mod[x % m] = 1
	b = 0
	l = list(mod.keys())
	while b < len(mod.keys()):
		a = l[b]
		if mod[a] != 0:
			try:
				if mod[a] == mod[m - a]:
					ans += 1
					mod[a] = 0
					mod[m - a] = 0
				else:
					k = min(mod[a], mod[m - a]) + 1
					ans += 1
					mod[a] -= min(mod[a], k)
					mod[m - a] -= min(mod[m - a], k)
					ans += mod[a] or mod[m - a]
					(mod[a], mod[m - a]) = (0, 0)
			except:
				ans += mod[a]
				mod[a] = 0
		b += 1
	print(ans)


import collections
import os
import sys
if os.environ.get('NOT_JUDGE'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	(n, m) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	hm = collections.defaultdict(int)
	for x in arr:
		hm[x % m] += 1
	ans = 0
	for (k, v) in hm.items():
		if k == 0:
			ans += 1
		elif 2 * k == m:
			ans += 1
		elif 2 * k < m or m - k not in hm:
			(x, y) = (v, hm.get(m - k, 0))
			ans += 1 + max(0, abs(x - y) - 1)
	print(ans)

def main():
	n = int(input())
	for _ in range(n):
		solve()
main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	l = [0 for _ in range(m)]
	for c in a:
		l[c % m] += 1
	ans = 0
	i = 0
	while i <= m // 2:
		if i == m - i or i == 0:
			if l[i]:
				ans += 1
		elif l[i] == 0:
			if l[m - i] == 0:
				ans += 0
			else:
				ans += l[m - i]
		elif l[m - i] == 0:
			ans += l[i]
		elif abs(l[i] - l[m - i]) <= 1:
			ans += 1
		else:
			ans += max(l[i], l[m - i]) - min(l[i], l[m - i])
		i += 1
	print(ans)