#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
int n, m;
vector<int> e[maxn][10];
vector<int> val;
int main() {
  cin >> n >> m;
  int x, y, _n = n;
  for (int i = 1; i <= m; ++i) {
    cin >> x >> y;
    --x;
    --y;
    int _i = i;
    val.clear();
    while (_i) {
      val.push_back(_i % 10);
      _i /= 10;
    }
    reverse(val.begin(), val.end());
    auto add = [&](int u, int v) {
      int _u = u;
      for (int i = 0; i < val.size(); ++i) {
        if (i == val.size() - 1)
          e[_u][val[i]].push_back(v);
        else
          e[_u][val[i]].push_back(_n++);
        _u = _n - 1;
      }
    };
    add(x, y);
    add(y, x);
  }
  int rk = 0;
  queue<int> que;
  vector<int> dp(_n, 0);
  vector<vector<int>> vec;
  vec.emplace_back(vector<int>(1, rk++));
  vector<bool> vis(_n, false);
  que.push(0);
  while (!que.empty()) {
    int u = que.front();
    que.pop();
    for (int i = 0; i < 10; ++i) {
      vector<int> tmp;
      for (auto &_u : vec[u]) {
        for (auto &_v : e[_u][i]) {
          if (!vis[_v]) {
            vis[_v] = true;
            dp[_v] = (dp[_u] * 10LL + i) % mod;
            tmp.emplace_back(_v);
          }
        }
      }
      if (!tmp.empty()) {
        vec.push_back(std::move(tmp));
        que.push(rk++);
      }
    }
  }
  for (int i = 1; i < n; ++i) {
    cout << dp[i] << "\n";
  }
  cout << flush;
  return 0;
}
