M=998244353 K=int(input()) N=0 a=1 f=1 l=0 q=[] for _ in range(K): nl,m=map(int,input().split()) while l