""" 答えを見た 30段になるまでは、mod2でやってok """ import sys from sys import stdin def nCr_Plane(n,r): if n < r or n < 0: return 0 import math return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) def nCr_Lucas(n,r,mod): ret = 1 while n > 0 and r > 0: ret = (ret * nCr_Plane(n % mod , r % mod)) % mod n //= mod r //= mod return ret TT = int(stdin.readline()) ANS = [] for loop in range(TT): N,M = map(int,stdin.readline().split()) A = list(map(int,stdin.readline().split())) FOOT = 32 if len(A) >= FOOT: a_tmp = [] for slide in range(FOOT): #B = A[slide : slide + (N-FOOT+1)] #print (B) top = 0 for i in range(N-FOOT+1): if A[i+slide] & 1 and (N-FOOT)|i == (N-FOOT): top ^= 1 #(A[i+slide] % 2) * nCr_Lucas(N-FOOT,i,2) a_tmp.append(top) A = a_tmp mod = 2**M while len(A) > 1: B = [] for i in range(len(A)-1): B.append( (A[i]+A[i+1])**2 % mod ) A = B ANS.append(A[0] % mod) print (*ANS,sep="\n")