import sys input = sys.stdin.readline 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(32): 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] class SparseTable: def __init__(self, a, func=max, one=-10**18): self.table = [a[:]] self.n = len(a) self.logn = self.n.bit_length() self.func = func self.one = one for i in map(lambda x: 1 << x, range(self.logn - 1)): self.table.append([]) for j in range(self.n - i * 2 + 1): self.table[-1].append(self.func(self.table[-2][j], self.table[-2][j + i])) def get_section(self, i, j): length = j - i log = length.bit_length() - 1 if length <= 0: return self.one return self.func(self.table[log][i], self.table[log][j - (1 << log)]) sp = SparseTable([[i] if i != 0 else[] for i in a], merge_base, []) 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(sp.get_section(j, k)) print(pow(2, power, mod))