from math import gcd import sys, time, random from collections import deque, Counter, defaultdict def debug(*x):print('debug:',*x, file=sys.stderr) input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 61 - 1 def solve(): n, x = mi() c = li() maxc = -1 for i in range(n): if not (1 & (x >> c[i])): maxc = max(maxc, c[i]) if maxc == -1: print(0) return else: cost = inf if x > (1 << (maxc + 1)): cost = (x % (1 << (maxc + 1)) + 1) cost = min(cost, (x | ((1 << (maxc + 1)) - 1)) - (1 << maxc) + 1 - x) print(2 * cost) for _ in range(ii()): solve()