MOD = 10 ** 9 + 7 n, m = map(int, input().split()) leader = [[i] for i in range(n)] parent = [-1] * n def find(x): if parent[x] < 0: return x parent[x] = find(parent[x]) return parent[x] def unite(x, y): x = find(x) y = find(y) if x == y: return if parent[x] > parent[y]: x, y = y, x leader[x], leader[y] = leader[y], leader[x] elif parent[x] == parent[y]: leader[x] += leader[y] parent[x] += parent[y] parent[y] = x for _ in range(m): a, b = map(int, input().split()) unite(a - 1, b - 1) ans = [0] * n for i in range(n): if parent[i] < 0: x = pow(len(leader[i]), MOD - 2, MOD) for j in leader[i]: ans[j] = x print(*ans, sep="\n")