#include <bits/stdc++.h>
using namespace std;
int rk[1000005], now = 1, d1, d2;
struct Str {
  int p, fa, d;
  bool friend operator<(Str x1, Str x2) {
    if (rk[x1.fa] == rk[x2.fa])
      return x1.d > x2.d;
    else
      return rk[x1.fa] > rk[x2.fa];
  }
} top;
priority_queue<Str> Q;
long long ans[1000005];
int cnt;
pair<int, int> pr;
vector<pair<int, int>> ve[1000005];
void add(int s, int t, int d) {
  while (d >= 10) {
    cnt++;
    pr.first = d % 10;
    d /= 10;
    pr.second = s;
    ve[cnt].push_back(pr);
    s = cnt;
  }
  pr.first = d;
  pr.second = s;
  ve[t].push_back(pr);
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, m, u, v;
  cin >> n >> m;
  cnt = n;
  for (int i = 1; i <= m; i++) {
    cin >> u >> v;
    add(u, v, i);
    add(v, u, i);
  }
  top.p = 1;
  top.fa = 1;
  top.d = 0;
  Q.push(top);
  d1 = 1;
  d2 = 0;
  while (!Q.empty()) {
    top = Q.top();
    Q.pop();
    if (!rk[top.p]) {
      u = top.p;
      ans[u] = (ans[top.fa] * 10 + top.d) % 1000000007;
      if (rk[top.fa] != d1 || top.d != d2) {
        now++;
        d1 = rk[top.fa];
        d2 = top.d;
      }
      rk[u] = now;
      top.fa = u;
      for (int i = 0; i < (int)ve[u].size(); i++) {
        top.p = ve[u][i].second;
        top.d = ve[u][i].first;
        Q.push(top);
      }
    }
  }
  for (int i = 2; i <= n; i++) cout << ans[i] << endl;
  return 0;
}
