T = int(input()) for _ in range(T): N, X = map(int, input().split()) C = list(map(int, input().split())) ans = 0 for c in C: if X >> c & 1 == 0: mask = ((1 << c) - 1) & X ans = max(ans, ((X | (1 << c)) ^ mask) - X) print(2 * ans)