#include <bits/stdc++.h>
using namespace std;
const int maxn = 102000 * 10, MOD = 1000000007;
int add(int x, int y) { return x + y >= MOD ? x + y - MOD : x + y; }
int mul(int x, int y) { return 1LL * x * y % MOD; }
vector<int> G[maxn][10];
int tot, n, m, ans[maxn];
void addEdge(int x, int y, int id) {
  while (id >= 10) {
    int np = ++tot;
    G[np][id % 10].push_back(y);
    y = np, id /= 10;
  }
  G[x][id].push_back(y);
}
bool vis[maxn];
void bfs() {
  vector<vector<int> > q1, q2;
  q1.emplace_back(1, 1);
  vis[1] = true;
  while (!q1.empty()) {
    for (auto st : q1) {
      for (int w = 0; w < 10; ++w) {
        vector<int> nst;
        for (auto u : st)
          for (auto v : G[u][w])
            if (!vis[v]) {
              vis[v] = true, ans[v] = add(mul(10, ans[u]), w);
              nst.push_back(v);
            }
        if (!nst.empty()) q2.push_back(nst);
      }
    }
    q1 = q2, q2.clear();
  }
}
int main() {
  scanf("%d%d", &n, &m), tot = n;
  for (int i = 1; i <= m; ++i) {
    int from, to;
    scanf("%d%d", &from, &to);
    addEdge(from, to, i);
    addEdge(to, from, i);
  }
  bfs();
  for (int i = 2; i <= n; ++i) printf("%d\n", ans[i]);
  return 0;
}
