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