N = 19 dat = [None for _ in range(N)] for _ in range(N): L,*A = map(int,input().split()) dat[_] = set(A) dp = [[0] * 2 for _ in range(1 << N)] dp[0][0] = 1 for bit in range(1 << N): n = 0 for i in range(N): if bit >> i & 1: n += 1 m = 0 for i in range(N): if bit >> i & 1: m += 1 else: if i + 1 not in dat[n]:continue dp[bit | (1 << i)][(n - m) % 2] += dp[bit][0] dp[bit | (1 << i)][(n - m + 1) % 2] += dp[bit][1] print(dp[-1][0],dp[-1][1])