mod = 998244353 eps = 10**-9 def main(): import sys from itertools import combinations input = sys.stdin.readline N = int(input()) A = [] PE = [] P = {} for i in range(N): M = int(input()) a = 1 D = {} for j in range(M): p, e = map(int, input().split()) if p not in P: P[p] = 0 P[p] = max(P[p], e) a *= p ** e D[p] = e A.append(a) PE.append(D) B = [] BA = [] BB = [] B_val = [] for i in range(N): D = PE[i] b = set() val = 1 for p in D: if D[p] == P[p]: b.add(p) val *= p if b: B.append(b) BA.append(A[i]) B_val.append(val) else: BB.append(A[i]) for i, b in enumerate(B): ok = 0 for pp in P: if pp not in b: # ans[j].append(BA[i]) ok = 1 break if not ok: print(-1) exit() L = len(P) P_list = list(P.keys()) cov = [0] * (L+1) seen = set() for b, val in zip(B, B_val): if val not in seen: seen.add(val) cov[len(b)] += 1 B_val = list(set(B_val)) comb = L for k in range(2, L+1): comb *= (L - k + 1) comb //= k if cov[k] == comb: continue for J in combinations(P_list, k): J = list(J) q = 1 for pp in J: q *= pp ans = [[] for _ in range(k)] flg = 1 for i, b in enumerate(B_val): if b % q == 0: flg = 0 break if flg: for i, b in enumerate(B): for j, pp in enumerate(J): if pp not in b: ans[j].append(BA[i]) break ans[0].extend(BB) print(k) for a in ans: a = [len(a)] + a print(*a) exit() if __name__ == '__main__': main()