using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var half = 500_000_004; var c = NList; var (n, m) = (c[0], c[1]); var map = NArr(m); var uf = new UnionFindTree(n); var tree = new List<(int to, int len)>[n + m]; for (var i = 0; i < tree.Length; ++i) tree[i] = new List<(int to, int len)>(); var addcnt = 0; var adds = new int[n]; for (var i = 0; i < n; ++i) adds[i] = i; var refs = new int[n + m]; for (var i = 0; i < m; ++i) { var a = map[i][0] - 1; var b = map[i][1] - 1; if (!uf.IsSameTree(a, b)) { var pa = adds[uf.GetRoot(a)]; var pb = adds[uf.GetRoot(b)]; var nc = addcnt + n; var la = 0; var lb = 0; if (uf.GetSize(a) > uf.GetSize(b)) la = 1; else if (uf.GetSize(b) > uf.GetSize(a)) lb = 1; else { la = half; lb = half; } tree[nc].Add((pa, la)); tree[nc].Add((pb, lb)); uf.Unite(a, b); adds[uf.GetRoot(a)] = nc; ++addcnt; ++refs[pa]; ++refs[pb]; } } var len = new long[n]; for (var i = 0; i < tree.Length; ++i) { if (refs[i] == 0) DFS(i, 1, tree, len); } WriteLine(string.Join("\n", len)); } static int mod = 1_000_000_007; static void DFS(int cur, long val, List<(int to, int len)>[] tree, long[] len) { if (cur < len.Length) len[cur] = val; foreach (var next in tree[cur]) { DFS(next.to, val * next.len % mod, tree, len); } } class UnionFindTree { int[] roots; public UnionFindTree(int size) { roots = new int[size]; for (var i = 0; i < size; ++i) roots[i] = -1; } public int GetRoot(int a) { if (roots[a] < 0) return a; return roots[a] = GetRoot(roots[a]); } public bool IsSameTree(int a, int b) { return GetRoot(a) == GetRoot(b); } public bool Unite(int a, int b) { var x = GetRoot(a); var y = GetRoot(b); if (x == y) return false; if (-roots[x] < -roots[y]) { var tmp = x; x = y; y = tmp; } roots[x] += roots[y]; roots[y] = x; return true; } public int GetSize(int a) { return -roots[GetRoot(a)]; } } }