You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare. 

In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words he has vectors with m coordinates, each one equal either 0 or 1. Vector addition is defined as follows: let u+v = w, then w_i = (u_i + v_i) mod 2. 

Euclid can sum any subset of S and archive another m-dimensional vector over Z_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 0.

Let T be the set of all the vectors that can be written as a sum of some vectors from S. Now Euclid wonders the size of T and whether he can use only a subset S' of S to obtain all the vectors from T. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in S have at most 2 coordinates equal 1. 

Help Euclid and calculate |T|, the number of m-dimensional vectors over Z_2 that can be written as a sum of some vectors from S. As it can be quite large, calculate it modulo 10^9+7. You should also find S', the smallest such subset of S, that all vectors in T can be written as a sum of vectors from S'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input. 

Consider sets A and B such that |A| = |B|. Let a_1, a_2, ... a_{|A|} and b_1, b_2, ... b_{|B|} be increasing arrays of indices elements of A and B correspondingly. A is lexicographically smaller than B iff there exists such i that a_j = b_j for all j < i and a_i < b_i.

Input

In the first line of input, there are two integers n, m (1 ≤ n, m ≤ 5 ⋅ 10^5) denoting the number of vectors in S and the number of dimensions. 

Next n lines contain the description of the vectors in S. In each of them there is an integer k (1 ≤ k ≤ 2) and then follow k distinct integers x_1, ... x_k (1 ≤ x_i ≤ m). This encodes an m-dimensional vector having 1s on coordinates x_1, ... x_k and 0s on the rest of them.

Among the n vectors, no two are the same.

Output

In the first line, output two integers: remainder modulo 10^9+7 of |T| and |S'|. In the second line, output |S'| numbers, indices of the elements of S' in ascending order. The elements of S are numbered from 1 in the order they are given in the input.

Examples

Input


3 2
1 1
1 2
2 2 1


Output


4 2
1 2 


Input


2 3
2 1 3
2 1 2


Output


4 2
1 2 


Input


3 5
2 1 2
1 3
1 4


Output


8 3
1 2 3 

Note

In the first example we are given three vectors: 

  * 10 
  * 01 
  * 11 



It turns out that we can represent all vectors from our 2-dimensional space using these vectors: 

  * 00 is a sum of the empty subset of above vectors; 
  * 01 = 11 + 10, is a sum of the first and third vector; 
  * 10 = 10, is just the first vector; 
  * 11 = 10 + 01, is a sum of the first and the second vector. 



Hence, T = \{00, 01, 10, 11\}. We can choose any two of the three vectors from S and still be able to obtain all the vectors in T. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in T using only a single vector from S, |S'| = 2 and S' = \{10, 01\} (indices 1 and 2), as set \{1, 2 \} is lexicographically the smallest. We can represent all vectors from T, using only vectors from S', as shown below: 

  * 00 is a sum of the empty subset; 
  * 01 = 01 is just the second vector; 
  * 10 = 10 is just the first vector; 
  * 11 = 10 + 01 is a sum of the first and the second vector.

Source: codeforces | Difficulty: HARD
Tags: Bit manipulation

Graph algorithms

Graph traversal

Sorting

Greedy algorithms

Mathematics

Spanning trees


Solutions:
import sys
input = sys.stdin.buffer.readline

def _find(s, u):
	p = []
	while s[u] != u:
		p.append(u)
		u = s[u]
	for v in p:
		s[v] = u
	return u

def _union(s, u, v):
	(su, sv) = (_find(s, u), _find(s, v))
	if su != sv:
		s[su] = sv
	return su != sv
(n, m) = map(int, input().split())
(s, solo) = (list(range(m + 1)), [0] * (m + 1))
(res, pos) = ([], set())
for i in range(n):
	p = list(map(int, input().split()))
	if p[0] == 1:
		pos.add(p[1])
		p1 = _find(s, p[1])
		if not solo[p1]:
			res.append(i + 1)
			solo[p1] = 1
	else:
		pos.add(p[1])
		pos.add(p[2])
		(p1, p2) = (_find(s, p[1]), _find(s, p[2]))
		if not (p1 == p2 or (solo[p1] and solo[p2])):
			_union(s, p1, p2)
			res.append(i + 1)
			if solo[p1] or solo[p2]:
				solo[_find(s, p1)] = 1
cc = 0
for u in pos:
	su = _find(s, u)
	cc += 1
	if not solo[su] and su == u:
		cc -= 1
print(pow(2, cc, 10 ** 9 + 7), len(res))
print(*res)


class UnionFind:

	def __init__(self, n):
		self.parent = list(range(n))

	def find(self, a):
		acopy = a
		while a != self.parent[a]:
			a = self.parent[a]
		while acopy != a:
			(self.parent[acopy], acopy) = (a, self.parent[acopy])
		return a

	def union(self, a, b):
		self.parent[self.find(b)] = self.find(a)
import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
UF = UnionFind(m + 1)
MOD = 10 ** 9 + 7
out = []
for i in range(1, n + 1):
	l = list(map(int, input().split()))
	if len(l) == 2:
		u = 0
		v = l[1]
	else:
		(_, u, v) = l
	uu = UF.find(u)
	vv = UF.find(v)
	if uu != vv:
		UF.union(uu, vv)
		out.append(i)
print(pow(2, len(out), MOD), len(out))
print(' '.join(map(str, out)))


import sys
input = sys.stdin.buffer.readline

def prog():
	(n, m) = map(int, input().split())
	mod = 10 ** 9 + 7
	has_one = [0] * (m + 1)
	basis = []
	sizes = [1] * (m + 1)
	parent = list(range(m + 1))

	def find_parent(v):
		if v == parent[v]:
			return v
		v = find_parent(parent[v])
		return v

	def union_sets(a, b):
		a = find_parent(a)
		b = find_parent(b)
		if a != b and (not has_one[a] or not has_one[b]):
			if sizes[a] < sizes[b]:
				(a, b) = (b, a)
			parent[b] = a
			sizes[a] += sizes[b]
			has_one[a] = has_one[a] | has_one[b]
			return True
		else:
			return False
	for i in range(1, n + 1):
		a = list(map(int, input().split()))
		if a[0] == 1:
			par = find_parent(a[1])
			if not has_one[par]:
				has_one[par] = 1
				basis.append(i)
		elif union_sets(a[1], a[2]):
			basis.append(i)
	print(pow(2, len(basis), mod), len(basis))
	print(*basis)
prog()


MOD = 10 ** 9 + 7
import sys
input = sys.stdin.buffer.readline

class UnionFind:

	def __init__(self, n):
		self.parent = list(range(n))

	def find(self, a):
		acopy = a
		while a != self.parent[a]:
			a = self.parent[a]
		while acopy != a:
			(self.parent[acopy], acopy) = (a, self.parent[acopy])
		return a

	def union(self, a, b):
		self.parent[self.find(b)] = self.find(a)

def oneLineArrayPrint(arr):
	print(' '.join([str(x + 1) for x in arr]))

def solveActual():
	uf = UnionFind(m + 2)
	for (i, x) in enumerate(vS):
		if len(x) == 1:
			x.append(m + 1)
		x.append(i)
	vS.sort(key=lambda x: x[2])
	sPrime = []
	for (p1, p2, index) in vS:
		if uf.find(p1) != uf.find(p2):
			uf.union(p1, p2)
			sPrime.append(index)
	TSize = pow(2, len(sPrime), MOD)
	print('{} {}'.format(TSize, len(sPrime)))
	oneLineArrayPrint(sPrime)
(n, m) = [int(x) for x in input().split()]
vS = []
for _ in range(n):
	xx = [int(x) for x in input().split()]
	for i in range(1, len(xx)):
		xx[i] -= 1
	vS.append(xx[1:])
solveActual()


import sys
input = sys.stdin.readline
mod = 1000000007
(n, m) = map(int, input().split())
ans = []
groupi = [-1] * (m + 1)
groups = [2] * m
for i in range(m):
	groups[i] = []
cur = 1
for i in range(n):
	x = list(map(int, input().split()))
	k = x.pop(0)
	if k == 1:
		x = x[0]
		if groupi[x] == -1:
			groupi[x] = 0
			ans.append(i + 1)
		if groupi[x] > 0:
			ind = groupi[x]
			for y in groups[ind]:
				groupi[y] = 0
			groupi[x] = 0
			ans.append(i + 1)
	if k == 2:
		(x1, x2) = (x[0], x[1])
		if groupi[x1] == -1:
			if groupi[x2] == -1:
				groupi[x1] = cur
				groupi[x2] = cur
				groups[cur] = [x1, x2]
				cur += 1
				ans.append(i + 1)
			elif groupi[x2] == 0:
				groupi[x1] = 0
				ans.append(i + 1)
			else:
				groupi[x1] = groupi[x2]
				groups[groupi[x2]].append(x1)
				ans.append(i + 1)
		elif groupi[x2] == -1:
			if groupi[x1] == 0:
				groupi[x2] = 0
				ans.append(i + 1)
			else:
				groupi[x2] = groupi[x1]
				groups[groupi[x1]].append(x2)
				ans.append(i + 1)
		elif groupi[x1] != groupi[x2]:
			if groupi[x1] == 0 or groupi[x2] == 0:
				if groupi[x1] == 0:
					for y in groups[groupi[x2]]:
						groupi[y] = 0
				else:
					for y in groups[groupi[x1]]:
						groupi[y] = 0
			else:
				if len(groups[groupi[x1]]) < len(groups[groupi[x2]]):
					(x1, x2) = (x2, x1)
				for y in groups[groupi[x2]]:
					groupi[y] = groupi[x1]
					groups[groupi[x1]].append(y)
			ans.append(i + 1)
print(pow(2, len(ans), mod), len(ans))
print(*ans)


import sys

def input():
	return sys.stdin.buffer.readline()[:-1]

class UnionFind:

	def __init__(self, size):
		self.table = [-1 for _ in range(size)]

	def find(self, x):
		while self.table[x] >= 0:
			if self.table[self.table[x]] >= 0:
				self.table[x] = self.table[self.table[x]]
			x = self.table[x]
		return x

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def unite(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			r1 = self.table[s1]
			r2 = self.table[s2]
			if r1 <= r2:
				self.table[s2] = s1
				if r1 == r2:
					self.table[s1] -= 1
			else:
				self.table[s1] = s2
		return
(m, n) = map(int, input().split())
uf = UnionFind(n + 1)
ans = []
for i in range(1, m + 1):
	q = list(map(int, input().split()))
	if q[0] == 1:
		if uf.same(q[1] - 1, n):
			continue
		else:
			ans.append(i)
			uf.unite(q[1] - 1, n)
	elif uf.same(q[1] - 1, q[2] - 1):
		continue
	else:
		ans.append(i)
		uf.unite(q[1] - 1, q[2] - 1)
print(pow(2, len(ans), 10 ** 9 + 7), len(ans))
print(*ans)


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

class DSU:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.has_loop = [False] * n

	def find(self, v):
		if v == self.parent[v]:
			return v
		self.parent[v] = self.find(self.parent[v])
		return self.parent[v]

	def union(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a != b:
			if self.size[a] < self.size[b]:
				(a, b) = (b, a)
			self.parent[b] = a
			self.size[a] += self.size[b]
			self.has_loop[b] = self.has_loop[a] = self.has_loop[a] or self.has_loop[b]

def solve():
	(n, m) = map(int, input().split())
	dsu = DSU(m)
	ans = []
	for i in range(n):
		(k, *r) = map(int, input().split())
		if k == 1:
			x = r[0] - 1
			if not dsu.has_loop[dsu.find(x)]:
				dsu.has_loop[dsu.find(x)] = True
				ans.append(i + 1)
		else:
			(u, v) = (r[0] - 1, r[1] - 1)
			if dsu.find(u) != dsu.find(v) and (not (dsu.has_loop[dsu.find(u)] and dsu.has_loop[dsu.find(v)])):
				dsu.union(u, v)
				ans.append(i + 1)
	print(pow(2, len(ans), 10 ** 9 + 7), len(ans))
	print(*ans)
t = 1
for _ in range(t):
	solve()


import sys, io, os
from collections import deque
try:
	Z = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
except:
	Z = lambda : sys.stdin.readline().encode()
Y = lambda : map(int, Z().split())
M = 10 ** 9 + 7
(n, N) = Y()

def path(R):
	H = deque()
	H.append(R)
	while P[R] >= 0:
		R = P[R]
		H.append(R)
		if len(H) > 2:
			P[H.popleft()] = H[-1]
	return R
K = [-1] * N
P = [-1] * N
S = [1] * N
R = 0
B = []
alr = [0] * N
for i in range(n):
	k = (*Y(),)
	if k[0] < 2:
		a = k[1] - 1
		if K[a] >= 0:
			v = path(K[a])
			if not alr[v]:
				alr[v] = 1
			else:
				continue
		else:
			K[a] = R
			v = R
			alr[R] = 1
			R += 1
		B.append(i + 1)
		continue
	a = k[1] - 1
	b = k[2] - 1
	if K[a] >= 0:
		if K[b] >= 0:
			(va, vb) = (path(K[a]), path(K[b]))
			if va == vb or (alr[va] and alr[vb]):
				pass
			else:
				(sa, sb) = (S[va], S[vb])
				if sa > sb:
					P[vb] = va
				else:
					P[va] = vb
					if sa == sb:
						S[vb] += 1
				B.append(i + 1)
				if alr[va]:
					alr[vb] = 1
				if alr[vb]:
					alr[va] = 1
		else:
			K[b] = path(K[a])
			B.append(i + 1)
	elif K[b] >= 0:
		vb = K[a] = path(K[b])
		B.append(i + 1)
	else:
		K[a] = R
		K[b] = R
		R += 1
		B.append(i + 1)
B.sort()
s = len(B)
print(pow(2, s, M), s)
print(' '.join(map(str, B)))


from sys import stdin, stdout
(n, m) = [int(i) for i in stdin.readline().split()]
l = []
d1 = {}
a = []
p = [i for i in range(m)]
r = [0 for i in range(m)]
mod = 10 ** 9 + 7

def find(x):
	while p[x] != x:
		x = p[x]
	return x

def power(x):
	f = 1
	ct = 2
	while x:
		if x % 2 == 1:
			f = f * ct
			f %= mod
		ct = ct * ct
		ct %= mod
		x //= 2
	return f
for i in range(n):
	x = [int(j) - 1 for j in stdin.readline().split()][1:]
	if len(x) == 1:
		x[0] = find(x[0])
		if d1.get(x[0], 0) == 0:
			l.append(i)
			d1[x[0]] = 1
	else:
		(u, v) = (find(x[0]), find(x[1]))
		if d1.get(u, 0) == 1 and d1.get(v, 0) == 1:
			continue
		elif u == v:
			continue
		elif d1.get(u, 0) == 1:
			d1[v] = 1
			l.append(i)
		elif d1.get(v, 0) == 1:
			d1[u] = 1
			l.append(i)
		else:
			px = u
			py = v
			if r[px] > r[py]:
				p[py] = px
			elif r[px] < r[py]:
				p[px] = py
			else:
				p[py] = px
				r[px] += 1
			l.append(i)
stdout.write(str(power(len(l))) + ' ' + str(len(l)) + '\n')
for i in l:
	stdout.write(str(i + 1) + ' ')


from collections import defaultdict
import sys
input = sys.stdin.readline

class UF:

	def __init__(self, N):
		self.par = list(range(N))
		self.sz = [1] * N

	def find(self, x):
		if self.par[x] != x:
			self.par[x] = self.find(self.par[x])
		return self.par[x]

	def union(self, x, y):
		(xr, yr) = (self.find(x), self.find(y))
		if xr == yr:
			return False
		if self.sz[xr] < self.sz[yr]:
			(xr, yr) = (yr, xr)
		self.par[yr] = xr
		self.sz[xr] += self.sz[yr]
		return True

	def size(self, x):
		return self.sz[self.find(x)]

	def connected(self, x, y):
		return self.find(x) == self.find(y)
(n, m) = list(map(int, input().split(' ')))
cur_count = 1
cur_lst = []
uf = UF(m + 2)
for i in range(n):
	bit_lst = list(map(int, input().split(' ')))
	bit1 = bit_lst[1]
	bit2 = m + 1
	if bit_lst[0] == 2:
		bit2 = bit_lst[2]
	if uf.union(bit1, bit2):
		cur_lst.append(str(i + 1))
		cur_count *= 2
		cur_count %= 10 ** 9 + 7
print(cur_count, len(cur_lst))
print(' '.join(cur_lst))


import sys
input = sys.stdin.buffer.readline

def _find(s, u):
	p = []
	while s[u] != u:
		p.append(u)
		u = s[u]
	for v in p:
		s[v] = u
	return u

def _union(s, u, v):
	(su, sv) = (_find(s, u), _find(s, v))
	if su != sv:
		s[su] = sv
(n, m) = map(int, input().split())
(s, res) = (list(range(m + 1)), [])
for i in range(n):
	p = list(map(int, input().split()))
	if p[0] == 1:
		(u, v) = (0, p[1])
	else:
		(u, v) = (p[1], p[2])
	(su, sv) = (_find(s, u), _find(s, v))
	if su != sv:
		_union(s, su, sv)
		res.append(i + 1)
print(pow(2, len(res), 10 ** 9 + 7), len(res))
print(*res)


import sys
input = sys.stdin.readline
(N, M) = map(int, input().split())
mod = 10 ** 9 + 7
base = [0] * (M + 1)
e = [[] for _ in range(M + 1)]
res = []

class UnionFind:

	def __init__(self, n):
		self.n = n
		self.root = [-1] * (n + 1)
		self.rnk = [0] * (n + 1)

	def Find_Root(self, x):
		if self.root[x] < 0:
			return x
		else:
			self.root[x] = self.Find_Root(self.root[x])
			return self.root[x]

	def Unite(self, x, y):
		x = self.Find_Root(x)
		y = self.Find_Root(y)
		if x == y:
			return
		elif self.rnk[x] > self.rnk[y]:
			self.root[x] += self.root[y]
			self.root[y] = x
		else:
			self.root[y] += self.root[x]
			self.root[x] = y
			if self.rnk[x] == self.rnk[y]:
				self.rnk[y] += 1

	def isSameGroup(self, x, y):
		return self.Find_Root(x) == self.Find_Root(y)

	def Count(self, x):
		return -self.root[self.Find_Root(x)]
uf = UnionFind(M)
for i in range(1, N + 1):
	a = list(map(int, input().split()))
	if a[0] == 1:
		a.append(0)
	(u, v) = a[1:]
	if uf.isSameGroup(u, v):
		continue
	else:
		uf.Unite(u, v)
		res.append(i)
print(pow(2, len(res), mod), len(res))
print(*res)


import sys
input = sys.stdin.readline
mod = 10 ** 9 + 7
(n, m) = map(int, input().split())
Group = [i for i in range(m + 1)]
GroupOne = [0] * (m + 1)
Nodes = [1] * (m + 1)

def find(x):
	while Group[x] != x:
		x = Group[x]
	return x

def Union(x, y):
	if find(x) != find(y):
		if Nodes[find(x)] < Nodes[find(y)]:
			Nodes[find(y)] += Nodes[find(x)]
			Nodes[find(x)] = 0
			if GroupOne[find(x)] == 1 or GroupOne[find(y)] == 1:
				GroupOne[find(x)] = 1
				GroupOne[find(y)] = 1
			Group[find(x)] = find(y)
		else:
			Nodes[find(x)] += Nodes[find(y)]
			Nodes[find(y)] = 0
			if GroupOne[find(x)] == 1 or GroupOne[find(y)] == 1:
				GroupOne[find(x)] = 1
				GroupOne[find(y)] = 1
			Group[find(y)] = find(x)
ANS = []
for i in range(n):
	V = tuple(map(int, input().split()))
	if V[0] == 1:
		x = V[1]
		if GroupOne[find(x)] == 0:
			ANS.append(i + 1)
			GroupOne[find(x)] = 1
		else:
			continue
	else:
		(x, y) = (V[1], V[2])
		if find(x) == find(y) or (GroupOne[find(x)] == 1 and GroupOne[find(y)] == 1):
			continue
		else:
			Union(x, y)
			ANS.append(i + 1)
print(pow(2, len(ANS), mod), len(ANS))
print(*ANS)


import sys
readline = sys.stdin.readline

class UF:

	def __init__(self, num):
		self.par = [-1] * num
		self.color = [0] * num

	def find(self, x):
		if self.par[x] < 0:
			return x
		else:
			stack = []
			while self.par[x] >= 0:
				stack.append(x)
				x = self.par[x]
			for xi in stack:
				self.par[xi] = x
			return x

	def col(self, x):
		return self.color[self.find(x)]

	def paint(self, x):
		self.color[self.find(x)] = 1

	def union(self, x, y):
		rx = self.find(x)
		ry = self.find(y)
		if rx != ry:
			if self.par[rx] > self.par[ry]:
				(rx, ry) = (ry, rx)
			self.par[rx] += self.par[ry]
			self.par[ry] = rx
			self.color[rx] |= self.color[ry]
			return True
		return False
(N, M) = map(int, readline().split())
MOD = 10 ** 9 + 7
ans = []
T = UF(M)
for m in range(N):
	(k, *x) = map(int, readline().split())
	if k == 1:
		u = x[0] - 1
		if not T.col(u):
			ans.append(m + 1)
			T.paint(u)
	else:
		(u, v) = (x[0] - 1, x[1] - 1)
		if T.col(u) and T.col(v):
			continue
		if T.union(u, v):
			ans.append(m + 1)
print(pow(2, len(ans), MOD), len(ans))
print(' '.join(map(str, ans)))


class UnionFindVerSize:

	def __init__(self, N):
		self._parent = [n for n in range(0, N)]
		self._size = [1] * N
		self.source = [False] * N
		self.group = N

	def find_root(self, x):
		if self._parent[x] == x:
			return x
		self._parent[x] = self.find_root(self._parent[x])
		stack = [x]
		while self._parent[stack[-1]] != stack[-1]:
			stack.append(self._parent[stack[-1]])
		for v in stack:
			self._parent[v] = stack[-1]
		return self._parent[x]

	def unite(self, x, y):
		gx = self.find_root(x)
		gy = self.find_root(y)
		if gx == gy:
			return
		self.group -= 1
		if self._size[gx] < self._size[gy]:
			self._parent[gx] = gy
			self._size[gy] += self._size[gx]
			self.source[gy] |= self.source[gx]
		else:
			self._parent[gy] = gx
			self._size[gx] += self._size[gy]
			self.source[gx] |= self.source[gy]

	def add_size(self, x):
		self.source[self.find_root(x)] = True

	def get_size(self, x):
		return self._size[self.find_root(x)]

	def get_source(self, x):
		return self.source[self.find_root(x)]

	def is_same_group(self, x, y):
		return self.find_root(x) == self.find_root(y)
import sys
input = sys.stdin.buffer.readline
(m, n) = map(int, input().split())
uf = UnionFindVerSize(n)
S = []
source = []
for i in range(m):
	edge = tuple(map(int, input().split()))
	if edge[0] == 1:
		v = edge[1]
		if not uf.get_source(v - 1):
			uf.add_size(v - 1)
			S.append(i + 1)
	else:
		(u, v) = (edge[1], edge[2])
		if not uf.is_same_group(u - 1, v - 1) and (not uf.get_source(u - 1) or not uf.get_source(v - 1)):
			uf.unite(u - 1, v - 1)
			S.append(i + 1)
ans = 1
k = 0
mod = 10 ** 9 + 7
for i in range(n):
	if uf.find_root(i) == i:
		if uf.get_source(i):
			k += uf.get_size(i)
		else:
			k += uf.get_size(i) - 1
print(pow(2, k, mod), len(S))
S.sort()
print(*S)


import io
import os
from collections import Counter, defaultdict, deque
MOD = 10 ** 9 + 7

class UnionFind:

	def __init__(self, N):
		self.p = [-1 for i in range(N)]

	def find(self, i):
		if self.p[i] >= 0:
			self.p[i] = self.find(self.p[i])
			return self.p[i]
		else:
			return i

	def union(self, i, j):
		root1 = self.find(j)
		root2 = self.find(i)
		if root1 == root2:
			return
		size1 = -self.p[root1]
		size2 = -self.p[root2]
		if size1 < size2:
			self.p[root1] = root2
			self.p[root2] = -(size1 + size2)
		else:
			self.p[root2] = root1
			self.p[root1] = -(size1 + size2)

	def getComponentSize(self, i):
		return -self.p[self.find(i)]

def solve(N, M, vectors):
	uf = UnionFind(M + 1)
	DUMMY_COMP = M
	ans = []
	for (i, v) in enumerate(vectors):
		if len(v) == 1:
			(a,) = v
			if uf.find(a) != uf.find(DUMMY_COMP):
				uf.union(a, DUMMY_COMP)
				ans.append(i)
		else:
			assert len(v) == 2
			(a, b) = v
			if uf.find(a) != uf.find(b):
				uf.union(a, b)
				ans.append(i)
	for i in range(M):
		uf.find(i)
	T = pow(2, uf.getComponentSize(DUMMY_COMP) - 1, MOD)
	T %= MOD
	seen = set()
	for i in range(M):
		comp = uf.find(i)
		if comp != uf.find(DUMMY_COMP) and comp not in seen:
			T *= pow(2, uf.getComponentSize(i) - 1, MOD)
			T %= MOD
			seen.add(comp)
	return str(T) + ' ' + str(len(ans)) + '\n' + ' '.join((str(i + 1) for i in ans))
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = 1
for tc in range(1, TC + 1):
	(N, M) = [int(x) for x in input().split()]
	vectors = [[int(x) - 1 for x in input().split()][1:] for i in range(N)]
	ans = solve(N, M, vectors)
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):

	def __init__(self, file):
		self.newlines = 0
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline()

def RL():
	return map(int, sys.stdin.readline().split())

def RLL():
	return list(map(int, sys.stdin.readline().split()))

def N():
	return int(input())

def S():
	return input().strip()

def print_list(l):
	print(' '.join(map(str, l)))

def find(region, u):
	path = []
	while region[u] != u:
		path.append(u)
		u = region[u]
	for v in path:
		region[v] = u
	return u

def union(region, u, v):
	(u, v) = (find(region, u), find(region, v))
	region[u] = v
	return u != v
M = 10 ** 9 + 7
(n, m) = RL()
region = list(range(m + 1))
ans = []
for i in range(1, n + 1):
	s = RLL()
	t = s[2] if s[0] == 2 else 0
	if union(region, s[1], t):
		ans.append(i)
res = 1
for _ in range(len(ans)):
	res = (res << 1) % M
print(res, len(ans))
print_list(ans)


import os
import sys
from io import BytesIO, IOBase

class UnionFind:

	def __init__(self, n):
		self.parent = list(range(n))

	def find(self, a):
		acopy = a
		while a != self.parent[a]:
			a = self.parent[a]
		while acopy != a:
			(self.parent[acopy], acopy) = (a, self.parent[acopy])
		return a

	def union(self, a, b):
		self.parent[self.find(b)] = self.find(a)

def main():
	(m, n) = map(int, input().split())
	ans = 0
	ans2 = []
	color = UnionFind(n + 1)
	for i in range(m):
		t = list(map(int, input().split()))
		if t[0] == 1:
			if color.find(n) != color.find(t[1] - 1):
				ans2.append(i + 1)
				color.union(n, t[1] - 1)
		elif color.find(t[2] - 1) != color.find(t[1] - 1):
			ans2.append(i + 1)
			color.union(t[2] - 1, t[1] - 1)
	print(str(pow(2, len(ans2), 10 ** 9 + 7)) + ' ' + str(len(ans2)))
	print(' '.join(map(str, ans2)))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = iter(sys.stdin.read().splitlines()).__next__

class UnionFind:

	def __init__(self, n):
		self.parent = list(range(n))

	def find(self, x):
		found = x
		while self.parent[found] != found:
			found = self.parent[found]
		while x != found:
			y = self.parent[x]
			self.parent[x] = found
			x = y
		return found

	def union(self, x, y):
		self.parent[self.find(x)] = self.find(y)
(n, m) = map(int, input().split())
S_prime = []
uf = UnionFind(m + 1)
for index in range(1, n + 1):
	vector_description = [int(i) - 1 for i in input().split()] + [m]
	(u, v) = vector_description[1:3]
	if uf.find(u) == uf.find(v):
		continue
	S_prime.append(index)
	uf.union(u, v)
T_size = pow(2, len(S_prime), 10 ** 9 + 7)
print(T_size, len(S_prime))
print(*sorted(S_prime))


from __future__ import division, print_function
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from math import gcd, factorial, floor, ceil, sqrt, log2
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def testcase(t):
	for pp in range(t):
		solve(pp)

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	y %= p - 1
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
inf = pow(10, 21)
mod = 10 ** 9 + 7

def bucketsort(order, seq):
	buckets = [0] * (max(seq) + 1)
	for x in seq:
		buckets[x] += 1
	for i in range(len(buckets) - 1):
		buckets[i + 1] += buckets[i]
	new_order = [-1] * len(seq)
	for i in reversed(order):
		x = seq[i]
		idx = buckets[x] = buckets[x] - 1
		new_order[idx] = i
	return new_order

def ordersort(order, seq, reverse=False):
	bit = max(seq).bit_length() >> 1
	mask = (1 << bit) - 1
	order = bucketsort(order, [x & mask for x in seq])
	order = bucketsort(order, [x >> bit for x in seq])
	if reverse:
		order.reverse()
	return order

def long_ordersort(order, seq):
	order = ordersort(order, [int(i & 2147483647) for i in seq])
	return ordersort(order, [int(i >> 31) for i in seq])

def multikey_ordersort(order, *seqs, sort=ordersort):
	for i in reversed(range(len(seqs))):
		order = sort(order, seqs[i])
	return order

class DisjointSetUnion:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n

	def find(self, a):
		acopy = a
		while a != self.parent[a]:
			a = self.parent[a]
		while acopy != a:
			(self.parent[acopy], acopy) = (a, self.parent[acopy])
		return a

	def union(self, a, b):
		(a, b) = (self.find(a), self.find(b))
		if a != b:
			if self.size[a] < self.size[b]:
				(a, b) = (b, a)
			self.num_sets -= 1
			self.parent[b] = a
			self.size[a] += self.size[b]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

def solve(case):
	(n, m) = sep()
	dsu = DisjointSetUnion(m + 1)
	take = [1] * n
	for index in range(n):
		a = lis()
		if a[0] == 1:
			(i, j) = (0, a[1])
		else:
			(i, j) = (a[1], a[2])
		grp1 = dsu.find(i)
		grp2 = dsu.find(j)
		if grp1 == grp2:
			take[index] = 0
		else:
			dsu.union(i, j)
	ans = []
	for i in range(n):
		if take[i]:
			ans.append(i)
	ans = sorted(ans)
	print(power(2, len(ans), mod), len(ans))
	print(' '.join((str(i + 1) for i in ans)))
testcase(1)


from collections import defaultdict
MOD = 10 ** 9 + 7
import sys
input = sys.stdin.buffer.readline

class UnionFind:

	def __init__(self, n):
		self.parent = list(range(n))

	def find(self, a):
		acopy = a
		while a != self.parent[a]:
			a = self.parent[a]
		while acopy != a:
			(self.parent[acopy], acopy) = (a, self.parent[acopy])
		return a

	def union(self, a, b):
		self.parent[self.find(b)] = self.find(a)

def oneLineArrayPrint(arr):
	print(' '.join([str(x + 1) for x in arr]))

def canTake(newEdgesCnt, newVerticesCnt, newHasOne):
	if newHasOne:
		return newEdgesCnt <= newVerticesCnt
	else:
		return newEdgesCnt <= newVerticesCnt - 1

def handleOne(i, v1, sPrime, cEc, cVc, cHO, vV, uf):
	parent = uf.find(v1)
	oldEdgesCnt = cEc[parent]
	oldVerticesCnt = cVc[parent]
	newEdgesCnt = oldEdgesCnt + 1
	if vV[v1] == False:
		newVerticesCnt = oldVerticesCnt + 1
	else:
		newVerticesCnt = oldVerticesCnt
	if canTake(newEdgesCnt, newVerticesCnt, True):
		sPrime.append(i)
		vV[v1] = True
		cEc[parent] = newEdgesCnt
		cVc[parent] = newVerticesCnt
		cHO[parent] = True
	return

def handleTwo(i, v1, v2, sPrime, cEc, cVc, cHO, vV, uf):
	parent1 = uf.find(v1)
	parent2 = uf.find(v2)
	if parent1 != parent2:
		oldEdgesCnt = cEc[parent1] + cEc[parent2]
		oldVerticesCnt = cVc[parent1] + cVc[parent2]
	else:
		oldEdgesCnt = cEc[parent1]
		oldVerticesCnt = cVc[parent1]
	newEdgesCnt = oldEdgesCnt + 1
	newVerticesCnt = oldVerticesCnt
	if vV[v1] == False:
		newVerticesCnt += 1
	if vV[v2] == False:
		newVerticesCnt += 1
	if canTake(newEdgesCnt, newVerticesCnt, cHO[parent1] or cHO[parent2]):
		sPrime.append(i)
		vV[v1] = True
		vV[v2] = True
		uf.union(v1, v2)
		newParent = uf.find(v1)
		cEc[newParent] = newEdgesCnt
		cVc[newParent] = newVerticesCnt
		cHO[newParent] = cHO[parent1] or cHO[parent2]
	return

def solveActual():
	uf = UnionFind(m)
	sPrime = []
	cEc = [0 for _ in range(m)]
	cVc = [0 for _ in range(m)]
	cHO = [False for _ in range(m)]
	vV = [False for _ in range(m)]
	for (i, x) in enumerate(vS):
		nVertices = len(x)
		if nVertices == 1:
			handleOne(i, x[0], sPrime, cEc, cVc, cHO, vV, uf)
		else:
			handleTwo(i, x[0], x[1], sPrime, cEc, cVc, cHO, vV, uf)
	TSize = pow(2, len(sPrime), MOD)
	print('{} {}'.format(TSize, len(sPrime)))
	oneLineArrayPrint(sPrime)
(n, m) = [int(x) for x in input().split()]
vS = []
for _ in range(n):
	xx = [int(x) for x in input().split()]
	for i in range(1, len(xx)):
		xx[i] -= 1
	vS.append(xx[1:])
solveActual()


import sys
input = sys.stdin.buffer.readline

class UnionFind:

	def __init__(self, n):
		self.parent = list(range(n))

	def find(self, a):
		acopy = a
		while a != self.parent[a]:
			a = self.parent[a]
		while acopy != a:
			(self.parent[acopy], acopy) = (a, self.parent[acopy])
		return a

	def union(self, a, b):
		self.parent[self.find(b)] = self.find(a)

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))
(n, m) = [int(x) for x in input().split()]
uf = UnionFind(m + 1)
hasOne = [False for _ in range(m + 1)]
sPrime = []
for i in range(n):
	inp = [int(x) for x in input().split()]
	if inp[0] == 1:
		parent = uf.find(inp[1])
		if hasOne[parent] == False:
			sPrime.append(i + 1)
			hasOne[parent] = True
	else:
		(parent1, parent2) = (uf.find(inp[1]), uf.find(inp[2]))
		if parent1 != parent2:
			if not (hasOne[parent1] and hasOne[parent2]):
				sPrime.append(i + 1)
				uf.union(inp[1], inp[2])
				newParent = uf.find(inp[1])
				hasOne[newParent] = hasOne[parent1] or hasOne[parent2]
S_magnitude = len(sPrime)
T_magnitude = pow(2, S_magnitude, 10 ** 9 + 7)
print('{} {}'.format(T_magnitude, S_magnitude))
oneLineArrayPrint(sPrime)


import sys
input = sys.stdin.readline
MOD = 10 ** 9 + 7

class UnionFind:

	def __init__(self, n):
		self.n = n
		self.parents = [-1] * n

	def find(self, x):
		if self.parents[x] < 0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if x == y:
			return
		if self.parents[x] > self.parents[y]:
			(x, y) = (y, x)
		self.parents[x] += self.parents[y]
		self.parents[y] = x

	def size(self, x):
		return -self.parents[self.find(x)]

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def members(self, x):
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i) == root]

	def roots(self):
		return [i for (i, x) in enumerate(self.parents) if x < 0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		dic = {r: [] for r in self.roots()}
		for i in range(self.n):
			dic[self.find(i)].append(i)
		return dic

	def __str__(self):
		return '\n'.join(('{}: {}'.format(r, self.members(r)) for r in self.roots()))

def main():
	(n, m) = map(int, input().split())
	ans = []
	UF = UnionFind(m + 1)
	for i in range(1, n + 1):
		q = list(map(int, input().split()))
		if q[0] == 1:
			x = 0
			y = q[1]
		else:
			x = q[1]
			y = q[2]
		if not UF.same(x, y):
			ans.append(i)
			UF.union(x, y)
	cnt = 0
	for x in UF.roots():
		cnt += UF.size(x) - 1
	t = pow(2, cnt, MOD)
	print(t, len(ans))
	print(*ans)
for _ in range(1):
	main()


import os, sys
from io import BytesIO, IOBase
from collections import deque

def find(parent, x):
	if x == parent[x]:
		return x
	parent[x] = find(parent, parent[x])
	return parent[x]

def union(parent, a, b, rank):
	(a, b) = (find(parent, a), find(parent, b))
	if a != b:
		if rank[a] < rank[b]:
			(a, b) = (b, a)
		parent[b] = a
		if rank[a] == rank[b]:
			rank[a] += 1
		return 1
	return 0

def main():
	(n, m) = map(int, input().split())
	(ans, rank) = ([], [0] * m)
	(parent, inde, path) = ([i for i in range(m)], [0] * m, [[] for _ in range(m)])
	for i in range(1, n + 1):
		x = list(map(int, input().split()))
		if x[0] == 1:
			a = x[1] - 1
			if not inde[a]:
				curr = deque([a])
				while len(curr):
					xx = curr.popleft()
					inde[xx] = 1
					for z in path[xx]:
						if not inde[z]:
							inde[z] = 1
							curr.append(z)
					path[xx] = []
				ans.append(i)
		else:
			(a, b) = (x[1] - 1, x[2] - 1)
			if (not inde[a] or not inde[b]) and union(parent, a, b, rank):
				path[a].append(b)
				path[b].append(a)
				if inde[a] or inde[b]:
					curr = deque([a])
					while len(curr):
						xx = curr.popleft()
						inde[xx] = 1
						for z in path[xx]:
							if not inde[z]:
								inde[z] = 1
								curr.append(z)
						path[xx] = []
				ans.append(i)
	print(pow(2, len(ans), 10 ** 9 + 7), len(ans))
	print(*ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.buffer.readline

class UnionFind:

	def __init__(self, n):
		self.parent = [-1] * n
		self.n = n
		self.cnt = n

	def root(self, x):
		if self.parent[x] < 0:
			return x
		else:
			self.parent[x] = self.root(self.parent[x])
			return self.parent[x]

	def merge(self, x, y):
		x = self.root(x)
		y = self.root(y)
		if x == y:
			return False
		if self.parent[x] > self.parent[y]:
			(x, y) = (y, x)
		self.parent[x] += self.parent[y]
		self.parent[y] = x
		self.cnt -= 1
		return True

	def is_same(self, x, y):
		return self.root(x) == self.root(y)

	def size(self, x):
		return -self.parent[self.root(x)]

	def count(self):
		return self.cnt

	def groups(self):
		res = [[] for _ in range(self.n)]
		for i in range(self.n):
			res[self.root(i)].append(i)
		return [group for group in res if group]
(n, m) = map(int, input().split())
info = [list(map(int, input().split())) for i in range(n)]
MOD = 10 ** 9 + 7
uf = UnionFind(m)
start = []
res = []
for (i, (k, *vs)) in enumerate(info):
	if len(vs) == 2:
		(u, v) = vs
		u -= 1
		v -= 1
		if not uf.is_same(u, v):
			uf.merge(u, v)
			res.append(i + 1)
	else:
		u = vs[0] - 1
		if start:
			if not uf.is_same(start[-1], u):
				uf.merge(start[-1], u)
				res.append(i + 1)
				start.append(u)
		else:
			res.append(i + 1)
			start.append(u)
print(pow(2, len(res), MOD), len(res))
print(*res)