#####segfunc##### def merge_func(x, y): new_base=[x[i] for i in range(len(x)) if x[i]!=0] for c in y: for b in new_base: c=min(c,c^b) if c: new_base.append(c) return new_base ################# #####ide_ele##### ide_ele = [] ################# class SparseTable(): def __init__(self,A,merge_func,ide_ele): N=len(A) n=N.bit_length() self.table=[[ide_ele for i in range(n)] for i in range(N)] self.merge_func=merge_func for i in range(N): self.table[i][0]=A[i] for j in range(1,n): for i in range(0,N-2**j+1): f=self.table[i][j-1] s=self.table[i+2**(j-1)][j-1] self.table[i][j]=self.merge_func(f,s) def query(self,s,t): b=t-s+1 m=b.bit_length()-1 return len(self.merge_func(self.table[s][m],self.table[t-2**m+1][m])) debug=False import sys input=sys.stdin.buffer.readline N,Q=map(int,input().split()) A=list(map(lambda x:[int(x)],input().split())) base_seg=SparseTable(A,merge_func,ide_ele) mod=10**9+7 for _ in range(Q): m=int(input()) b=[-1]+list(map(lambda x:int(x)-1,input().split()))+[N-1] ans=1 for i in range(1,m+2): L=b[i-1]+1 R=b[i] base=base_seg.query(L,R) cnt=R-L+1 ans*=pow(2,cnt-base,mod) ans%=mod print(ans)