def main(): n, m = list(map(int, input().split())) node = [[] for _ in range(n)] for _ in range(m): u, v, x = list(map(lambda x: int(x)-1, input().split())) node[u].append((v, x)) D = [-1] * n E = [-1] * n D[0] = 0 B = [0] while A:= B: B = [] for now in A: for nxt, x in node[now]: if D[nxt] == -1: if x == 0: D[nxt] = D[now]+1 B.append(nxt) elif nxt == n-1: print("Different") return D[now] + 1 if D[n-1] == -1: print("Unknown") return 0 else: print("Same") return D[n-1] for _ in range(int(input())): ans = main() if ans: print(ans)