import sys from itertools import permutations input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) import random def cmb(n, r, mod): if ( r<0 or r>n ): return 0 return (g1[n] * g2[r] % mod) * g2[n-r] % mod mod = 998244353 N = 2*10**5 g1 = [1]*(N+1) g2 = [1]*(N+1) inverse = [1]*(N+1) for i in range( 2, N + 1 ): g1[i]=( ( g1[i-1] * i ) % mod ) inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod ) g2[i]=( (g2[i-1] * inverse[i]) % mod ) inverse[0]=0 def brute(N,M,A): tmp = [-1] * N def dfs(i): if i == N: for j in range(N): s,b = 0,0 for k in range(N): if tmp[k] < tmp[j]: s+= 1 elif tmp[j] < tmp[k]: b += 1 if max(s,b)!=A[j]: return 0 #print(tmp) return 1 res = 0 for a in range(1,M+1): tmp[i] = a res += dfs(i+1) tmp[i] = -1 return res return dfs(0) def solve_brute(N,M,A): mask = 2**M-1 while len(A)!=1: A = [((A[i]+A[i+1])**2) & mask for i in range(len(A)-1)] return A[0] for _ in range(int(input())): N,M = mi() A = li() if N <= 2*M+10: print(solve_brute(N,M,A)) continue nA = [0] * (2*M) for i in range(2*M): for j in range(i,i+(N-2*M)+1): if A[j] & 1 and (N-2*M) & (j-i) == j-i: nA[i] ^= 1 A = nA print(solve_brute(N,M,nA))