Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

You are given an array A consisting of N integers and an integer X. Your goal is to have as many equal integers as possible in the array. To achieve this goal, you can do the following operation:
Choose an index i (1 ≤ i ≤ N)  and set A_{i} = A_{i} \oplus X,  where \oplus denotes the [bitwise xor operation].

Find the maximum number of equal integers you can have in the final array and the minimum number of operations to obtain these many equal integers. 

------ Input Format ------ 

- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- Each test case contains two lines of input.
- The first line of each test case contains two space-separated integers N, X.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}.

------ Output Format ------ 

For each test case, print a single line containing two space-separated integers - first, the maximum number of equal integers in the final array and second, the minimum number of operations to achieve these many equal integers. 

------ Constraints ------ 

$1 ≤ T ≤ 10^{4}$
$1 ≤ N ≤ 10^{5}$
$0 ≤ X ≤ 10^{9}$
$0 ≤ A_{i} ≤ 10^{9}$
- The sum of $N$ over all test cases does not exceed $5 \cdot 10^{5}$.

------ subtasks ------ 

Subtask #1 (100 points): Original constraints

----- Sample Input 1 ------ 
3
3 2
1 2 3
5 100
1 2 3 4 5
4 1
2 2 6 6

----- Sample Output 1 ------ 
2 1
1 0
2 0

----- explanation 1 ------ 
Test case $1$: One way to obtain $2$ equal integers is to set $A_{1} = A_{1} \oplus 2 $ $\; = 1 \oplus 2 = 3$. So the array becomes $[3, 2, 3]$. There is no way to obtain $3$ equal integers in the final array.

Test case $2$: There is no way to obtain more than one equal integer.

Source: codechef | Difficulty: MEDIUM_HARD
Tags: Bit manipulation

Data structures

Mathematics


Solutions:
for test in range(int(input())):
	(n, x) = map(int, input().split())
	nlist = list(map(int, input().split()))
	d = {}
	ans1 = ans2 = 0
	for i in nlist:
		d[i] = d.get(i, 0) + 1
		ans1 = max(ans1, d[i])
	for i in d:
		curr = i ^ x
		if curr == i:
			continue
		if d.get(curr, 0) + d[i] > ans1:
			ans1 = d.get(curr, 0) + d[i]
			ans2 = d[i]
		elif d.get(curr, 0) + d[i] == ans1:
			ans2 = min(ans2, d[i])
	print(ans1, ans2)


from collections import Counter
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	ac = Counter(a)
	maxe = 1
	mino = 0
	for c in ac:
		d = c ^ x
		if d in ac and d != c:
			mc = ac[c] + ac[d]
			mo = min(ac[c], ac[d])
		else:
			mc = ac[c]
			mo = 0
		if mc > maxe or (mc == maxe and mo < mino):
			maxe = mc
			mino = mo
	print('{} {}'.format(maxe, mino))


for t in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	d = dict()
	for i in a:
		if i not in d:
			d[i] = 0
		d[i] += 1
	e = dict()
	for i in a:
		if i ^ x not in e:
			e[i ^ x] = 0
		e[i ^ x] += 1
	ans = [0, 1000000000]
	if x == 0:
		print(max(d.values()), 0)
		continue
	for i in d:
		temp = [d.get(i, 0) + e.get(i, 0), e.get(i, 0)]
		if ans[0] < temp[0]:
			ans = temp
		elif ans[0] == temp[0]:
			ans = min(ans, temp)
	print(*ans)


import sys
input = sys.stdin.readline
from collections import defaultdict
for _ in range(int(input())):
	ctr = defaultdict(lambda : 0)
	mp = defaultdict(lambda : 0)
	(p, q) = (1, 0)
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	for x in a:
		ctr[x] += 1
	for x in a:
		if m != 0:
			mp[x ^ m] += 1
	for x in a:
		if mp[x] + ctr[x] > p:
			p = mp[x] + ctr[x]
			q = mp[x]
		if mp[x] + ctr[x] == p:
			q = min(q, mp[x])
	print(p, q)


King = int(input())
for i in range(King):
	(nn, x) = map(int, input().split())
	d = {}
	aa = list(map(int, input().split()))
	for i in aa:
		d[i] = d.get(i, 0) + 1
	e = o = 0
	for i in aa:
		nrml = d.get(i, 0)
		xor = d.get(i ^ x, 0)
		ans = nrml + xor
		if i != i ^ x:
			if e < ans:
				e = ans
				o = xor
			elif e == ans and o > xor:
				e = ans
				o = xor
		elif e < nrml:
			e = nrml
			o = 0
	print(e, o)


import collections
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	d = dict(collections.Counter(l))
	(m, opr) = (max(d.values()), 0)
	if x != 0:
		for i in l:
			cnt = d[i] + d.get(i ^ x, 0)
			if cnt > m:
				m = cnt
				opr = d[i]
			elif cnt == m:
				opr = min(opr, d[i])
	print(m, opr)


cases = int(input())
for i in range(cases):
	(N, X) = map(int, input().split(' '))
	li = list(map(int, input().split(' ')))
	dic = {}
	maxval = 0
	for j in li:
		if j not in dic:
			dic[j] = 1
		else:
			dic[j] += 1
		maxval = max(maxval, dic[j])
	op = 0
	for (key, val) in dic.items():
		cnt = val
		if key ^ X in dic:
			if X != 0:
				cnt += dic[key ^ X]
			req = dic[key ^ X]
		else:
			req = 0
		if cnt > maxval:
			maxval = cnt
			op = req
		elif cnt == maxval:
			op = min(op, req)
	print(maxval, op)


import numpy as np
from collections import Counter
for _ in range(int(input())):
	(nn, x) = map(int, input().split())
	d = {}
	aa = list(map(int, input().split()))
	for i in aa:
		d[i] = d.get(i, 0) + 1
	e = o = 0
	for i in aa:
		nrml = d.get(i, 0)
		xor = d.get(i ^ x, 0)
		ans = nrml + xor
		if i != i ^ x:
			if e < ans:
				e = ans
				o = xor
			elif e == ans and o > xor:
				e = ans
				o = xor
		elif e < nrml:
			e = nrml
			o = 0
	print(e, o)


t = int(input().strip())
while t > 0:
	t -= 1
	(n, x) = map(int, input().strip().split())
	arr = list(map(int, input().strip().split()))
	d1 = {}
	mx = 0
	for i in arr:
		d1.setdefault(i, 0)
		d1[i] += 1
		mx = max(mx, d1[i])
	ops = 0
	for i in arr:
		xor = i ^ x
		d1.setdefault(xor, 0)
		f = d1[i]
		if x != 0:
			f += d1[xor]
		if mx < f:
			mx = f
			ops = d1[xor]
		elif mx == f:
			ops = min(ops, d1[xor])
	print(mx, ops)


t = int(input())
while t > 0:
	t -= 1
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	d2 = {}
	c = []
	for i in a:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
		if i ^ x in d and x != 0:
			c.append(i)
			if i in d2:
				d2[i] += 1
			else:
				d2[i] = 1
	noc = -10000000000
	yesc = -10000000000
	count = 0
	for i in c:
		if yesc < d[i ^ x] + d[i]:
			yesc = d[i ^ x] + d[i]
			count = min(d[i ^ x], d[i])
		elif yesc == d[i ^ x] + d[i]:
			count = min(count, d[i ^ x], d[i])
	for i in d:
		noc = max(noc, d[i])
	if yesc <= noc:
		count = 0
	ans = max(noc, yesc)
	print(ans, count)


from collections import defaultdict
import os
for _ in range(int(input())):
	(n, v) = list(map(int, input().split(' ')))
	m = {}
	m = defaultdict(lambda : 0, m)
	is_present = {}
	is_present = defaultdict(lambda : 0, is_present)
	l = list(map(int, input().split(' ')))
	result = 1
	changes = 0
	for q in l:
		m[q] += 1
	for q in l:
		if v != 0:
			is_present[q ^ v] += 1
	for q in l:
		if is_present[q] + m[q] > result:
			result = m[q] + is_present[q]
			changes = is_present[q]
		if is_present[q] + m[q] == result:
			changes = min(changes, is_present[q])
	print(result, changes)


from collections import defaultdict

def readInt():
	return int(input())

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

def readString():
	return input().rstrip()

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

def readCase():
	(n, x) = readInts()
	nums = readInts()
	return (n, x, nums)

def solve(n, x, nums):
	(results, results_ops) = (defaultdict(int), defaultdict(int))
	best = 0
	best_ops = 0
	for m in nums:
		results[m] += 1
		if x != 0:
			m2 = m ^ x
			results[m2] += 1
			results_ops[m2] += 1
		else:
			m2 = m
		for y in (m, m2):
			if results[y] > best:
				best = results[y]
				best_ops = results_ops[y]
			elif results[y] == best:
				best_ops = min(best_ops, results_ops[y])
	return f'{best} {best_ops}'
cases = readInt()
for case in range(cases):
	print(solve(*readCase()))


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	dic = {}
	for i in arr:
		if i in dic:
			dic[i] += 1
		else:
			dic[i] = 1
	a = max(list(dic.values()))
	b = 0
	if k != 0:
		for i in list(dic.keys()):
			if i ^ k in dic:
				if dic[i] + dic[i ^ k] > a:
					a = dic[i] + dic[i ^ k]
					b = dic[i ^ k]
				elif dic[i] + dic[i ^ k] == a and dic[i ^ k] < b:
					b = dic[i ^ k]
	print(a, b)


T_T = int(input())
for i_i in range(T_T):
	(n_n, x_x) = map(int, input().split())
	d_d = {}
	a_a = list(map(int, input().split()))
	for i_i in a_a:
		d_d[i_i] = d_d.get(i_i, 0) + 1
	e_e = o_o = 0
	for i_i in a_a:
		nrml_nrml = d_d.get(i_i, 0)
		xor_xor = d_d.get(i_i ^ x_x, 0)
		ans_ans = nrml_nrml + xor_xor
		if i_i != i_i ^ x_x:
			if e_e < ans_ans:
				e_e = ans_ans
				o_o = xor_xor
			elif e_e == ans_ans and o_o > xor_xor:
				e_e = ans_ans
				o_o = xor_xor
		elif e_e < nrml_nrml:
			e_e = nrml_nrml
			o_o = 0
	print(e_e, o_o)


import math
import sys

def main():
	t = int(input())
	for z in range(t):
		a_counter = {}
		op_counter = {}
		result = 1
		data = input().split(' ')
		n = int(data[0])
		x = int(data[1])
		data = input().split(' ')
		a = [0] * n
		op_cnt = n + 1
		for i in range(n):
			val = int(data[i])
			a[i] = val
			a_total_cnt = a_counter.get(a[i])
			if a_total_cnt is None:
				xor = a[i] ^ x
				a_total_cnt = a_counter.get(xor)
				if a_total_cnt is not None:
					a_total_cnt = a_total_cnt + 1
					a_counter[xor] = a_total_cnt
					if result <= a_total_cnt:
						result = a_total_cnt
					op_cnt = op_counter.get(xor)
					if op_cnt is None:
						op_cnt = 0
					op_cnt = op_cnt + 1
					op_counter[xor] = op_cnt
				else:
					a_counter[a[i]] = 1
			else:
				a_total_cnt = a_total_cnt + 1
				a_counter[a[i]] = a_total_cnt
				if result < a_total_cnt:
					result = a_total_cnt
		if len(op_counter) == 0:
			print(result, 0)
			continue
		op_cnt = n + 1
		for key in a_counter.keys():
			if result == a_counter.get(key):
				if op_counter.get(key) is not None:
					if op_counter.get(key) <= result - op_counter.get(key):
						if op_counter.get(key) < op_cnt:
							op_cnt = op_counter.get(key)
					elif result - op_counter.get(key) < op_cnt:
						op_cnt = result - op_counter.get(key)
				else:
					op_cnt = 0
					break
		print(result, op_cnt)
main()


def main():
	T = int(input())
	a_cnt = dict()
	op_cnt = dict()
	while T > 0:
		T -= 1
		(N, X) = map(int, input().split())
		a_cnt.clear()
		op_cnt.clear()
		result = 1
		for a in map(int, input().split()):
			if a in a_cnt:
				a_cnt[a] += 1
				if a_cnt[a] > result:
					result = a_cnt[a]
			else:
				xora = a ^ X
				if xora not in a_cnt:
					a_cnt[a] = 1
				else:
					a_cnt[xora] += 1
					if xora in op_cnt:
						op_cnt[xora] += 1
					else:
						op_cnt[xora] = 1
					if a_cnt[xora] > result:
						result = a_cnt[xora]
		minop = N
		for (val, cnt) in a_cnt.items():
			if cnt == result:
				if val not in op_cnt:
					minop = 0
					break
				op = op_cnt[val]
				if op > cnt - op:
					op = cnt - op
				if op < minop:
					minop = op
		print(f'{result} {minop}')
main()


from sys import stdin
inp = stdin.readline
from collections import Counter

def main():
	T = int(inp())
	a_cnt = Counter()
	op_cnt = Counter()
	while T > 0:
		T -= 1
		(N, X) = map(int, inp().split())
		a_cnt.clear()
		op_cnt.clear()
		result = 1
		for a in map(int, inp().split()):
			if a_cnt[a] > 0:
				a_cnt[a] += 1
				if a_cnt[a] > result:
					result = a_cnt[a]
			else:
				xora = a ^ X
				if a_cnt[xora] == 0:
					a_cnt[a] = 1
				else:
					a_cnt[xora] += 1
					op_cnt[xora] += 1
					if a_cnt[xora] > result:
						result = a_cnt[xora]
		minop = N
		for (val, cnt) in a_cnt.items():
			if cnt == result:
				op = op_cnt[val]
				if op == 0:
					minop = 0
					break
				if op > cnt - op:
					op = cnt - op
				if op < minop:
					minop = op
		print(f'{result} {minop}')
main()


from sys import stdin
inp = stdin.readline
from collections import Counter
from operator import itemgetter
k1 = itemgetter(1)

def maxxor():
	(N, X) = map(int, inp().split())
	val_fq = Counter(map(int, inp().split()))
	if X == 0:
		(_, maxct) = val_fq.most_common(1)[0]
		return f'{maxct} 0'
	maxct = 0
	minop = N
	for (v, f) in sorted(val_fq.items(), key=k1, reverse=True):
		xf = val_fq[v ^ X]
		tot = f + xf
		if tot > maxct:
			maxct = tot
			minop = xf
		elif f * 2 <= maxct:
			break
	return f'{maxct} {minop}'
T = int(inp())
print(*(maxxor() for tx in range(T)), sep='\n')


from collections import defaultdict
for _ in range(int(input())):
	t = defaultdict(lambda : 0)
	mp = defaultdict(lambda : 0)
	(p, q) = (1, 0)
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	for x in a:
		t[x] += 1
	for x in a:
		if m != 0:
			mp[x ^ m] += 1
	for x in a:
		if mp[x] + t[x] > p:
			p = mp[x] + t[x]
			q = mp[x]
		if mp[x] + t[x] == p:
			q = min(q, mp[x])
	print(p, q)


from collections import defaultdict
try:
	t = int(input())
	for _ in range(t):
		(n, x) = map(int, input().split())
		a = [int(x) for x in input().split()]
		results = defaultdict(int)
		actual = defaultdict(int)
		for val in a:
			results[val] += 1
			actual[val] += 1
			if val ^ x != val:
				results[val ^ x] += 1
		(count, operations) = (0, 0)
		for (num, cnt) in results.items():
			if cnt > count:
				count = cnt
				operations = cnt - actual[num]
			elif cnt == count:
				operations = min(operations, cnt - actual[num])
		print(count, operations)
except:
	pass


from collections import defaultdict
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	d = defaultdict(int)
	if b == 0:
		for i in l:
			d[i] += 1
		x = -1
		for (i, j) in d.items():
			x = max(x, j)
		print(x, 0)
	else:
		for i in l:
			d[i] += 1
			d[i ^ b] += 1
		x = -1
		for (i, j) in d.items():
			x = max(x, j)
		l1 = []
		for (i, j) in d.items():
			if x == j:
				l1.append(i)
		y = 1000000000
		for i in l1:
			y = min(y, x - l.count(i))
		print(x, y)


def main():
	for _ in range(int(input())):
		(n, x) = map(int, input().split())
		arr = list(map(int, input().split()))
		(d1, d2) = ({}, {})
		for i in arr:
			d1[i] = d1.get(i, 0) + 1
			d2[i] = 1
		if n == 1:
			print(1, 0)
			continue
		(ans, step) = (0, 0)
		for i in d1:
			if d1[i] == n:
				ans = n
				break
			if d1[i] > ans:
				ans = d1[i]
		if x == 0:
			print(ans, step)
			continue
		for i in d2:
			t = i ^ x
			if d2.get(t, 0) == 1:
				if d1[i] + d1[t] > ans:
					ans = d1[t] + d1[i]
					step = min(d1[i], d1[t])
				elif d1[i] + d1[t] == ans:
					step = min(step, d1[i], d1[t])
		print(ans, step)
main()


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	lst = list(map(int, input().split()))
	mydict = {}
	for i in lst:
		if i in mydict:
			mydict[i] += 1
		else:
			mydict[i] = 1
	dict2 = {}
	for j in lst:
		xor = j ^ x
		if xor in dict2:
			dict2[xor] += 1
		else:
			dict2[xor] = 1
	max_value = max(mydict.values())
	oper = 0
	if x != 0:
		for a in dict2:
			if a in mydict:
				value = dict2[a] + mydict[a]
				if value > max_value:
					oper = dict2[a]
					max_value = value
				elif value == max_value:
					oper = min(oper, dict2[a])
				else:
					pass
	print(max_value, oper)


def sol():
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	li = {}
	ma = 1
	i = a.pop(0)
	mai = i
	li[i] = [1, 1, 0]
	for i in a:
		h = i ^ x
		if i in li:
			li[i][0] += 1
			li[i][1] += 1
			if li[i][0] > ma:
				ma = li[i][0]
				mai = i
			elif li[i][0] == ma and min(li[i][1], li[i][2]) < min(li[mai][1], li[mai][2]):
				ma = li[i][0]
				mai = i
		elif h in li:
			li[h][0] += 1
			li[h][2] += 1
			if li[h][0] > ma:
				ma = li[h][0]
				mai = h
			elif li[h][0] == ma and min(li[h][1], li[h][2]) < min(li[mai][1], li[mai][2]):
				ma = li[h][0]
				mai = h
		else:
			li[i] = [1, 1, 0]
	print(li[mai][0], min(li[mai][1], li[mai][2]))
t = int(input())
for i in range(t):
	sol()


for i in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	(d1, d2, max, min) = (dict(), dict(), 0, 0)
	for i in l:
		if i in d1:
			d1[i] += 1
		else:
			d1[i] = 1
		d2[i] = 0
	for i in l:
		if i ^ x != i:
			if i ^ x in d2:
				d2[i ^ x] += 1
			else:
				d2[i ^ x] = 1
			if i ^ x in d1:
				d1[i ^ x] += 1
			else:
				d1[i ^ x] = 1
	for i in l:
		if d1[i] >= max:
			if d1[i] == max and d2[i] > min:
				continue
			max = d1[i]
			if i in d2:
				min = d2[i]
			else:
				min = 0
	print(max, min)


import sys
input = sys.stdin.readline
t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	x = int(l[1])
	l = input().split()
	li = [int(i) for i in l]
	hashi = dict()
	cnt = dict()
	for i in li:
		if i not in hashi:
			hashi[i] = 0
		hashi[i] += 1
		if i ^ x not in hashi:
			hashi[i ^ x] = 0
		if i ^ x not in cnt:
			cnt[i ^ x] = 0
		hashi[i ^ x] += 1
		cnt[i ^ x] += 1
	maxa = 0
	req = 0
	for i in hashi:
		z = 0
		if i in cnt:
			z = cnt[i]
		if hashi[i] > maxa:
			maxa = hashi[i]
			req = z
		elif hashi[i] == maxa and z < req:
			req = z
	if x == 0:
		print(maxa // 2, 0)
	else:
		print(maxa, req)


from collections import *
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = [*map(int, input().split())]
	dic = Counter(l)
	ans = 0
	for i in dic:
		ans = max(ans, dic[i])
	operations = 0
	for i in dic:
		if i ^ x != i and i ^ x in dic:
			if ans <= dic[i] + dic[i ^ x]:
				if ans == dic[i] + dic[i ^ x]:
					operations = min(operations, dic[i])
				else:
					ans = dic[i] + dic[i ^ x]
					operations = dic[i]
	print(ans, operations)


from collections import defaultdict
for k in range(int(input())):
	a = defaultdict(lambda : 0)
	b = defaultdict(lambda : 0)
	(c, c1) = (1, 0)
	(n, m) = map(int, input().split())
	arr = list(map(int, input().strip().split()))
	for i in arr:
		a[i] += 1
	for i in arr:
		if m != 0:
			b[i ^ m] += 1
	for i in arr:
		if b[i] + a[i] > c:
			c = b[i] + a[i]
			c1 = b[i]
		if b[i] + a[i] == c:
			c1 = min(c1, b[i])
	print(c, c1)


T = int(input())
for _ in range(T):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	frequency = dict()
	xor_frequency = dict()
	counter = {}
	operation = {}
	for val in a:
		counter[val] = counter[val] + 1 if counter.get(val) else 1
		operation[val] = 0
	for val in a:
		if x != 0:
			xor = val ^ x
			counter[xor] = counter[xor] + 1 if counter.get(xor) else 1
			operation[xor] = operation[xor] + 1 if operation.get(xor) else 1
	max_val = 0
	min_val = 1e+18
	check = list()
	for (key, val) in counter.items():
		if val > max_val:
			max_val = val
			check = list()
			check.append(key)
		elif val == max_val:
			check.append(key)
	for item in check:
		min_val = min(min_val, operation[item])
	print('{} {}'.format(max_val, min_val))


for i in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	d = {}
	mx = 0
	for i in l:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	mx = max(d, key=lambda x: d[x])
	opr = 0
	val = d[mx]
	d_key = d.keys()
	if x == 0:
		print(val, opr)
		continue
	for i in d_key:
		v = i ^ x
		if v in d_key:
			t_mx = d[v] + d[i]
			if t_mx > val:
				val = t_mx
				opr = d[v]
			elif t_mx == val:
				opr = min(opr, d[v])
	print(val, opr)


from collections import defaultdict
for j in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	d = defaultdict(lambda : None)
	for i in range(n):
		if d[l[i]] == None:
			d[l[i]] = 0
		d[l[i]] += 1
	mx = max(d, key=lambda x: d[x])
	mx_v = d[mx]
	opr = 0
	if x == 0:
		print(mx_v, opr)
		continue
	for i in list(set(l)):
		xr = i ^ x
		cr = d[i]
		if xr in d:
			if mx_v < cr + d[xr]:
				mx_v = cr + d[xr]
				opr = d[xr]
			elif mx_v == cr + d[xr]:
				opr = min(opr, d[xr])
	print(mx_v, opr)


from collections import defaultdict
t = int(input())
for z in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	d = defaultdict(lambda : None)
	for i in range(n):
		if d[a[i]] == None:
			d[a[i]] = 0
		d[a[i]] += 1
	mx = max(d, key=lambda x: d[x])
	val = d[mx]
	step = 0
	if x == 0:
		print(val, step)
		continue
	for i in list(set(a)):
		temp = i ^ x
		curr = d[i]
		if d[temp] != None:
			if val < curr + d[temp]:
				val = curr + d[temp]
				step = d[temp]
			elif val == curr + d[temp]:
				step = min(step, d[temp])
	print(val, step)


from collections import defaultdict
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	max_count = 1
	data = defaultdict(int)
	for value in input().split():
		data[int(value)] += 1
		if data[int(value)] > max_count:
			max_count = data[int(value)]
	min_operation = 0
	for (key, value) in data.items():
		updated_value = value
		if x != 0:
			xor_key = key ^ x
			if xor_key in data:
				current_operation = data[xor_key]
			else:
				current_operation = 0
			updated_value += current_operation
		if updated_value > max_count:
			max_count = updated_value
			min_operation = current_operation
		elif updated_value == max_count:
			min_operation = min(min_operation, current_operation)
	print(f'{max_count} {min_operation}')


Shanmu = int(input())
for i in range(Shanmu):
	(num, x_1) = map(int, input().split())
	d_1 = {}
	a_1 = list(map(int, input().split()))
	for i in a_1:
		d_1[i] = d_1.get(i, 0) + 1
	e_1 = o = 0
	for i_1 in a_1:
		nrml_1 = d_1.get(i_1, 0)
		xor_1 = d_1.get(i_1 ^ x_1, 0)
		ans_1 = nrml_1 + xor_1
		if i_1 != i_1 ^ x_1:
			if e_1 < ans_1:
				e_1 = ans_1
				o_1 = xor_1
			elif e_1 == ans_1 and o_1 > xor_1:
				e_1 = ans_1
				o_1 = xor_1
		elif e_1 < nrml_1:
			e_1 = nrml_1
			o_1 = 0
	print(e_1, o_1)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	rec = {}
	xorDict = {}
	for i in range(n):
		if xorDict.get(arr[i] ^ x) != None:
			xorDict[arr[i] ^ x] += 1
		else:
			xorDict[arr[i] ^ x] = 1
		if rec.get(arr[i]) != None:
			rec[arr[i]] += 1
		else:
			rec[arr[i]] = 1
	mxEq = steps = 0
	for key in rec:
		if xorDict.get(key) != None:
			if xorDict[key] + rec[key] > mxEq or (xorDict[key] + rec[key] == mxEq and steps > xorDict[key]):
				mxEq = xorDict[key] + rec[key]
				steps = xorDict[key]
		if rec[key] >= mxEq:
			mxEq = rec[key]
			steps = 0
	if not x:
		mxEq = 0
		for i in rec:
			mxEq = max(mxEq, rec[i])
		steps = 0
	print(mxEq, steps)


import sys
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	my_map = {}
	ll = list(map(int, input().split()))
	for tmp in ll:
		my_map[tmp] = my_map.get(tmp, 0) + 1
	e = o = 0
	for i in ll:
		nrml = my_map.get(i)
		xorred = my_map.get(i ^ x, 0)
		ans = nrml + xorred
		if x != 0:
			if e < ans:
				e = ans
				o = xorred
			elif e == ans and o > xorred:
				o = xorred
		elif e < nrml:
			e = nrml
			o = 0
	print(e, o)


import sys
t = int(input())
for _ in range(t):
	(n, xor) = map(int, input().split())
	d = {}
	l = [int(x) for x in input().split()]
	for x in l:
		if x in d:
			d[x][0] += 1
		else:
			d[x] = [1, 0]
		if xor != 0:
			if x ^ xor in d:
				d[x ^ xor][0] += 1
				d[x ^ xor][1] += 1
			else:
				d[x ^ xor] = [1, 1]
	(minOp, maxCount) = (sys.maxsize, -sys.maxsize)
	for key in d:
		if d[key][0] > maxCount:
			maxCount = d[key][0]
			minOp = d[key][1]
		elif d[key][0] == maxCount:
			minOp = min(minOp, d[key][1])
	print(maxCount, minOp)


for i in range(int(input())):
	(n, x) = map(int, input().split())
	d = {}
	arr = [int(x) for x in input().split()]
	for i in arr:
		d[i] = d.get(i, 0) + 1
	a = b = 0
	for i in arr:
		ele = d.get(i, 0)
		res = d.get(i ^ x, 0)
		ans = ele + res
		if i != i ^ x:
			if a < ans:
				a = ans
				b = res
			elif a == ans and b > res:
				a = ans
				b = res
		elif a < ele:
			a = ele
			b = 0
	print(a, b)


for test in range(int(input())):
	(N, X) = [int(i) for i in input().split()]
	A = [int(i) for i in input().split()]
	dic = dict()
	for i in A:
		if i in dic:
			dic[i][0] += 1
		else:
			dic[i] = [1, 0]
		res = i ^ X
		if res == i:
			continue
		if res in dic:
			dic[res][0] += 1
			dic[res][1] += 1
		else:
			dic[res] = [1, 1]
	count = 0
	ops = 0
	for i in dic:
		if dic[i][0] > count:
			count = dic[i][0]
			ops = dic[i][1]
		elif dic[i][0] == count:
			if dic[i][1] < ops:
				ops = dic[i][1]
	print(count, ops)


for test in range(int(input())):
	(n, x) = [int(i) for i in input().split()]
	A = [int(i) for i in input().split()]
	dic = dict()
	for i in A:
		if i in dic:
			dic[i][0] += 1
		else:
			dic[i] = [1, 0]
		res = i ^ x
		if res == i:
			continue
		if res in dic:
			dic[res][0] += 1
			dic[res][1] += 1
		else:
			dic[res] = [1, 1]
	count = 0
	ops = 0
	for i in dic:
		if dic[i][0] > count:
			count = dic[i][0]
			ops = dic[i][1]
		elif dic[i][0] == count:
			if dic[i][1] < ops:
				ops = dic[i][1]
	print(count, ops)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	freq = {}
	for i in a:
		if i in freq:
			freq[i] += 1
		else:
			freq[i] = 1
	xor = {}
	for i in freq:
		num = i ^ x
		if i in xor:
			xor[i][0] += freq[i]
		else:
			xor[i] = [freq[i], 0]
		if num != i:
			if num in xor:
				xor[num][0] += freq[i]
				xor[num][1] += freq[i]
			else:
				xor[num] = [freq[i], freq[i]]
	max_equal = 0
	min_operations = n
	for (_, i) in xor.items():
		if i[0] > max_equal:
			max_equal = i[0]
			min_operations = i[1]
		elif i[0] == max_equal:
			min_operations = min(min_operations, i[1])
	print(max_equal, min_operations)


from collections import Counter
testcases = int(input())
while testcases:
	(N, X) = map(int, input().split())
	A = [int(i) for i in input().split()]
	occur = Counter(A)
	(max_times_repeat, min_ops_req) = (occur.most_common(1)[0][1], 0)
	if X == 0:
		print(max_times_repeat, min_ops_req)
		testcases -= 1
		continue
	xor_with_X = Counter()
	for each in occur:
		xor_with_X[each ^ X] = occur[each]
	for key in occur:
		if occur[key] + xor_with_X[key] > max_times_repeat:
			max_times_repeat = occur[key] + xor_with_X[key]
			min_ops_req = xor_with_X[key]
		elif occur[key] + xor_with_X[key] == max_times_repeat:
			min_ops_req = min(min_ops_req, xor_with_X[key])
	print(max_times_repeat, min_ops_req)
	testcases -= 1


from collections import defaultdict
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	d = defaultdict(lambda : 0)
	x_d = defaultdict(lambda : 0)
	(ans1, ans2) = (1, 0)
	for item in a:
		d[item] += 1
	for i in a:
		if x != 0:
			x_d[i ^ x] += 1
	for i in a:
		if x_d[i] + d[i] > ans1:
			ans1 = x_d[i] + d[i]
			ans2 = x_d[i]
		if x_d[i] + d[i] == ans1:
			ans2 = min(ans2, x_d[i])
	print(ans1, ans2)


from sys import stdin
inp = stdin.readline
from collections import Counter

def maxxor():
	(N, X) = map(int, inp().split())
	val_fq = Counter(map(int, inp().split()))
	if X == 0:
		(_, maxct) = val_fq.most_common(1)[0]
		return f'{maxct} 0'
	maxct = 0
	minop = N
	for (v, f) in val_fq.items():
		xf = val_fq[v ^ X]
		tot = f + xf
		if tot > maxct:
			maxct = tot
			minop = xf
		elif tot == maxct and xf < minop:
			minop = xf
	return f'{maxct} {minop}'
T = int(inp())
print(*(maxxor() for tx in range(T)), sep='\n')


from collections import defaultdict
for _ in range(int(input())):
	a = defaultdict(lambda : 0)
	b = defaultdict(lambda : 0)
	(x, y) = (1, 0)
	(o, p) = map(int, input().split())
	arr = list(map(int, input().strip().split()))
	for i in arr:
		a[i] += 1
	for i in arr:
		if p != 0:
			b[i ^ p] += 1
	for i in arr:
		if b[i] + a[i] > x:
			x = b[i] + a[i]
			y = b[i]
		if b[i] + a[i] == x:
			y = min(y, b[i])
	print(x, y)


T = int(input())
for i in range(T):
	d = dict()
	l = list(map(int, input().split()))
	x = l[1]
	A = list(map(int, input().split()))
	for j in range(len(A)):
		if A[j] in d.keys():
			d[A[j]] += 1
		else:
			d[A[j]] = 1
	mx = 0
	ops = 0
	for j in d.keys():
		if j ^ x in d.keys() and x != 0:
			if d[j ^ x] + d[j] > mx:
				mx = d[j ^ x] + d[j]
				ops = d[j]
			if d[j ^ x] + d[j] == mx:
				ops = min(ops, d[j])
		if d[j] >= mx:
			mx = d[j]
			ops = 0
	print(mx, ops)


tt = int(input())
for test in range(tt):
	(n, x) = map(int, input().split())
	aa = list(map(int, input().split()))
	bb = {}
	cc = {}
	for i in range(n):
		bb[aa[i]] = bb.get(aa[i], 0) + 1
	if x != 0:
		for j in range(n):
			dd = aa[j] ^ x
			cc[dd] = cc.get(dd, 0) + 1
	maxMax = 0
	op = n
	for i in bb:
		max = bb[i] + cc.get(i, 0)
		if max >= maxMax:
			if max == maxMax:
				if cc.get(i, 0) < op:
					op = cc.get(i, 0)
			else:
				maxMax = max
				op = cc.get(i, 0)
	for i in cc:
		if i in bb:
			continue
		max = cc[i]
		if max >= maxMax:
			if max == maxMax:
				if cc.get(i, 0) < op:
					op = cc.get(i, 0)
			else:
				maxMax = max
				op = cc.get(i, 0)
	print(maxMax, op)


for testcase in range(int(input())):
	(N, X) = map(int, input().split())
	values = list(map(int, input().split()))
	maxOccurenceCounts = 0
	valueCounts = {}
	for value in values:
		valueCounts[value] = valueCounts.get(value, 0) + 1
		maxOccurenceCounts = max(maxOccurenceCounts, valueCounts[value])
	if X == 0:
		print(maxOccurenceCounts, 0)
	else:
		XORValueCounts = {}
		minOperations = 0
		for value in valueCounts:
			XORValueCounts[value ^ X] = valueCounts[value]
		for value in valueCounts:
			if value in XORValueCounts:
				if valueCounts[value] + XORValueCounts[value] > maxOccurenceCounts:
					maxOccurenceCounts = valueCounts[value] + XORValueCounts[value]
					minOperations = XORValueCounts[value]
				elif valueCounts[value] + XORValueCounts[value] == maxOccurenceCounts:
					minOperations = min(XORValueCounts[value], minOperations)
		print(maxOccurenceCounts, min(minOperations, N - minOperations))


from sys import stdin
for testcase in range(int(stdin.readline())):
	(N, X) = map(int, stdin.readline().split())
	values = list(map(int, stdin.readline().split()))
	maxOccurenceCounts = 0
	valueCounts = {}
	for value in values:
		valueCounts[value] = valueCounts.get(value, 0) + 1
		maxOccurenceCounts = max(maxOccurenceCounts, valueCounts[value])
	if X == 0:
		print(maxOccurenceCounts, 0)
	else:
		XORValueCounts = {}
		for value in valueCounts:
			XORValueCounts[value ^ X] = valueCounts[value]
		minOperations = 0
		for value in valueCounts:
			if value in XORValueCounts:
				if valueCounts[value] + XORValueCounts[value] > maxOccurenceCounts:
					maxOccurenceCounts = valueCounts[value] + XORValueCounts[value]
					minOperations = XORValueCounts[value]
				elif valueCounts[value] + XORValueCounts[value] == maxOccurenceCounts:
					minOperations = min(XORValueCounts[value], minOperations)
		print(maxOccurenceCounts, min(minOperations, N - minOperations))


from collections import Counter
for _ in range(int(input())):
	LIST = []
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	c = Counter(a)
	operation = {}
	for i in a:
		operation[i] = 0
	for i in a:
		if i ^ x in c and i != i ^ x:
			c[i ^ x] = c[i ^ x] + 1
		elif i != i ^ x:
			c[i ^ x] = 1
		if i ^ x in operation and i != i ^ x:
			operation[i ^ x] += 1
		elif i != i ^ x:
			operation[i ^ x] = 1
	v = list(c.values())
	k = list(c.keys())
	value = max(v)
	for (k1, v1) in c.items():
		if v1 == value:
			k2 = k1
			LIST.append(k1)
	small = operation[LIST[0]]
	for k1 in LIST:
		if operation[k1] < small:
			small = operation[k1]
	key = k[v.index(max(v))]
	print(value, small)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	ele = list(map(int, input().split()))
	hm = dict()
	for e in ele:
		xo = e ^ x
		if e in hm:
			hm[e][0] += 1
		else:
			hm[e] = [1, 0]
		if x != 0 and xo in hm:
			hm[xo][0] += 1
			hm[xo][1] += 1
		elif x != 0:
			hm[xo] = [1, 1]
	it = [0, 0]
	for e1 in hm:
		if hm[e1][0] > it[0]:
			it = [hm[e1][0], hm[e1][1]]
		elif hm[e1][0] == it[0]:
			it[1] = min(hm[e1][1], it[1])
	print(it[0], it[1])


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	h1 = {}
	h2 = {}
	mf = -1
	for i in a:
		if i in h1:
			h1[i] += 1
		else:
			h1[i] = 1
		mf = max(h1[i], mf)
	for i in a:
		y = i ^ x
		if y in h2:
			h2[y] += 1
		else:
			h2[y] = 1
	ans = -1
	ans1 = -1
	op = 10000000007
	if x == 0:
		print(mf, 0)
	else:
		for i in h1:
			if i in h2:
				if h1[i] + h2[i] > ans:
					ans = h1[i] + h2[i]
					op = h2[i]
				elif h1[i] + h2[i] == ans and op > h2[i]:
					ans = h1[i] + h2[i]
					op = h2[i]
			elif h1[i] > ans1:
				ans1 = h1[i]
		if ans > ans1:
			print(ans, op)
		else:
			print(ans1, 0)


T = int(input())
for i in range(T):
	(N, X) = map(int, input().split())
	a = list(map(int, input().split()))
	dic = {}
	for j in range(N):
		if a[j] in dic:
			dic[a[j]] += 1
		else:
			dic[a[j]] = 1
	dic1 = list(dic.keys())
	maxi = 0
	for j in range(len(dic1)):
		if dic[dic1[j]] > maxi:
			maxi = dic[dic1[j]]
	ans1 = 0
	ans2 = 1000000000
	flag = 0
	if X == 0:
		print(maxi, 0)
	else:
		for j in range(len(dic1)):
			val = dic1[j] ^ X
			if val in dic.keys():
				b = dic[val]
				c = dic[dic1[j]] + b
				if c > maxi:
					flag = 1
					if ans1 < c:
						ans1 = c
		if flag == 0:
			print(maxi, 0)
		else:
			ans2 = 1000000000
			for j in range(len(dic1)):
				val = dic1[j] ^ X
				if val in dic.keys():
					b = dic[val]
					c = dic[dic1[j]] + b
					if c == ans1:
						d = min(dic[dic1[j]], b)
						if ans2 > d:
							ans2 = d
			print(ans1, ans2)


from collections import defaultdict

def main():
	t = int(input())
	for _ in range(t):
		(n, x) = map(int, input().split())
		l1 = list(map(int, input().split()))
		count_1_dir = defaultdict(lambda : 0)
		count_2_dir = defaultdict(lambda : 0)
		for i in l1:
			if i not in count_1_dir:
				count_1_dir[i] = 1
			else:
				count_1_dir[i] += 1
		for i in l1:
			if x != 0:
				if i ^ x in count_2_dir:
					count_2_dir[i ^ x] += 1
				else:
					count_2_dir[i ^ x] = 1
		p = 0
		q = 0
		for i in l1:
			if count_1_dir[i] + count_2_dir[i] > p:
				p = count_1_dir[i] + count_2_dir[i]
				q = count_2_dir[i]
			elif count_1_dir[i] + count_2_dir[i] == p:
				q = min(q, count_2_dir[i])
		print(p, q)
main()


from collections import *
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	(m, ans) = (1, 0)
	d1 = defaultdict(lambda : 0)
	d2 = defaultdict(lambda : 0)
	for i in range(len(l)):
		d1[l[i]] += 1
		if d1[l[i]] > m:
			m = d1[l[i]]
	if x == 0:
		print(m, x)
		continue
	for i in range(len(l)):
		d2[l[i] ^ x] += 1
	for i in range(len(l)):
		if d1[l[i]] + d2[l[i]] > m:
			m = d1[l[i]] + d2[l[i]]
			ans = d2[l[i]]
		if d1[l[i]] + d2[l[i]] == m:
			ans = min(ans, d2[l[i]])
	print(m, ans)


import numpy as np
from collections import Counter
import bisect
try:

	class Solution:

		def Final(self, N, X, arr):

			def BST(ele, arr):
				N = len(arr)
				k = bisect.bisect_left(arr, ele)
				if k != N and arr[k] == ele:
					return True
				return False
			count = Counter(arr)
			unique = list(count.keys())
			unique.sort()
			temp = list(count.values())
			temp.sort()
			if X == 0:
				print(temp[-1], 0)
				return
			ans = dict(count)
			M = {i: 0 for i in unique}
			status = {i: False for i in unique}
			for (i, v) in enumerate(unique):
				if status[v]:
					continue
				B = v ^ X
				if B != v and BST(B, unique):
					status[v] = True
					status[B] = True
					temp = count[B] + count[v]
					ans[v] += count[B]
					ans[B] += count[v]
					M[v] += count[B]
					M[B] += count[v]
			V = list(ans.values())
			V.sort()
			MM = list(M.values())
			Min = float('inf')
			for i in unique:
				if ans[i] == V[-1]:
					Min = min(Min, M[i])
			print(V[-1], Min)
	for t in range(int(input())):
		(N, X) = map(int, input().split())
		arr = list(map(int, input().split()))
		ans = Solution()
		ans.Final(N, X, arr)
except EOFError as e:
	print(e)


from collections import defaultdict
for _ in range(int(input())):
	(n, x) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	nums = set()
	curr_max = 0
	freq = defaultdict(lambda : 0)
	for i in arr:
		freq[i] += 1
		curr_max = max(curr_max, freq[i])
		nums.add(i)
	ops = 0
	for i in nums:
		sec_e = i ^ x
		if x != 0 and sec_e in nums:
			curr_f = freq[sec_e] + freq[i]
			if curr_f > curr_max:
				curr_max = curr_f
				ops = freq[sec_e]
			elif curr_f == curr_max:
				ops = min(ops, freq[sec_e])
	print(curr_max, ops)