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 = [] for i in range(N): D = PE[i] b = set() for p in D: if D[p] == P[p]: b.add(p) if b: B.append(b) BA.append(A[i]) else: BB.append(A[i]) L = len(P) P_list = list(P.keys()) for k in range(2, L+1): for J in combinations(P_list, k): J = list(J) ans = [[] for _ in range(k)] flg = 1 for i, b in enumerate(B): ok = 0 for j, pp in enumerate(J): if pp not in b: # ans[j].append(BA[i]) ok = 1 break if not ok: 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) for a in ans: a = [len(a)] + a print(*a) exit() print(-1) if __name__ == '__main__': main()