n, q = [int(i) for i in input().split()] a = [int(i) for i in input().split()] mod = 10**9+7 def merge_base(a, b): c = a + b i = 1 k = 0 for _ in range(40): for j in range(k, len(c)): if (i & c[j]) != 0: break else: i <<= 1 continue c[j], c[k] = c[k], c[j] for j in range(k + 1, len(c)): if (i & c[j]) != 0: c[j] ^= c[k] i <<= 1 k += 1 return c[:k] table = [[] for _ in range(15)] table[0] = [[i] if i != 0 else[] for i in a] for i in range(1, 15): for j in range(n - (1 << i) + 1): table[i].append(merge_base(table[i - 1][j], table[i - 1][j + (1 << (i-1))])) def get_section(i, j): k = (j - i).bit_length() - 1 return merge_base(table[k][i], table[k][j-(1 << k)]) for _ in range(q): m = int(input()) b = [0] for i in input().split(): b.append(int(i)) b.append(n) power = n for i in range(m + 1): j, k = b[i], b[i+1] power -= len(get_section(j, k)) print(pow(2, power, mod))