T=int(input()) def f(i,j): if (i,j) not in d: d[(i,j)]=(f(i-1,j)+f(i-1,j+1))**2 % 2**m return d[(i,j)] for _ in range(T): n,m=map(int,input().split()) L=list(map(int,input().split())) d=dict() for j in range(n): d[(0,j)]=L[j] print(f(n-1,0))