N, K = map(int, input().split()) G = [[[0 for _ in range(N)] for _ in range(N)] for _ in range(K)] t = [] mod = 998244353 for i in range(K): tmp = int(input()) t.append(tmp) for j in range(t[i]): a, b = map(int, input().split()) G[i][a-1][b-1] += 1 G[i][b-1][a-1] += 1 dp = [[0 for _ in range(1<