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


class UnionFind:  # based on submission 102831279
    def __init__(self, n):
        """ elements are 0, 1, 2, ..., n-1 """
        self.parent = list(range(n))
    
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])  # might reach recursion limit
            return self.parent[x]
    
    def union(self, x, y):
        self.parent[self.find(x)] = self.find(y)


n, m = map(int, input().split())
S = []
indices = {}
for index in range(n):
    vector_description = [int(i)-1 for i in input().split()] + [m]
    # one-hot vectors become (m, x_1)
    vec = tuple(sorted(vector_description[1:3], reverse=True))
    S.append(vec)
    indices[vec] = index+1

# redundant (linearly dependent) vectors would be part of cycle
S.sort(reverse=True)
S_prime = []
uf = UnionFind(m+1)
for u, v in S:
    print(uf.parent)
    print(u, v, uf.find(u), uf.find(v))
    if uf.find(u) == uf.find(v):
        continue
    S_prime.append((u, v))
    uf.union(u, v)

# 2**|S'| different sums among |S'| linearly independent vectors
T_size = pow(2, len(S_prime), 10**9+7)
print(T_size, len(S_prime))
# print(S_prime)
print(*sorted(map(indices.get, S_prime)))