Q=int(input()) for _ in range(Q): N,M=map(int,input().split()) G=[[] for i in range(N)] for i in range(M): a,b,c=map(int,input().split()) G[a-1].append((b-1,c)) G[b-1].append((a-1,c)) dist=[10**10]*(2*N) dist[0]=0 from collections import deque S=deque() S.append(0) while S: x=S.popleft() a,b=x//2,x&1 for B in G[a]: y,c=B[:] b2=b^(c-1) if dist[2*y+b2]==10**10: dist[2*y+b2]=dist[x]+1 S.append(2*y+b2) if dist[2*(N-1)]==10**10 and dist[2*(N-1)+1]==10**10: print('Unknown') else: if dist[2*(N-1)]<=dist[2*(N-1)+1]: print('Same') else: print('Different') print(min(dist[2*(N-1)],dist[2*(N-1)+1]))