def solve(): n, x = map(int, input().split()) C = list(map(int, input().split())) while C and (x >> C[-1]) & 1: C.pop() if not C: print(0) return c = C[-1] if x < (1 << c): ans = (1 << c) - x print(2 * ans) return t = x & ((1 << c) - 1) ans = min(t + 1, (1 << c) - t) print(2 * ans) for _ in range(int(input())): solve()