def main(): n, m = [int(i) for i in input().split()] uv = [[int(i) for i in input().split()] for i in range(m)] if m==n*(n-1)/2: print(3) out = [] u, v = uv[0] for a, b in uv: if (a, b) == (u, v): out.append(1) elif a==u or b==u: out.append(2) else: out.append(3) return " ".join([str(i) for i in out]) # Trouver un sommet de degré != n-1 degs = [0 for _ in range(n)] for u, v in uv: degs[u-1] += 1 degs[v-1] += 1 j=-1 for i in range(n): if degs[i] < n-1: j = i+1 break if j==-1: return print(2) out = [] for u, v in uv: if u==j or v==j: out.append(2) else: out.append(1) return " ".join([str(i) for i in out]) for _ in range(int(input())): print(main())