#include <bits/stdc++.h>
using namespace std;
long long n, t, m, sol[(int)(1e6 + 4)];
bitset<(int)(1e6 + 4)> used;
vector<pair<int, int>> g[(int)(1e6 + 4)];
void addEdge(int, int, int);
int main() {
  cin >> n >> m;
  t = n;
  for (int i = 1, x, y; i <= m; ++i) {
    cin >> x >> y;
    addEdge(x, y, i);
    addEdge(y, x, i);
  }
  used[1] = 1;
  vector<vector<int>> bucket = {{1}};
  for (int i = 0; i < bucket.size(); ++i) {
    vector<int> v = bucket[i], temp;
    vector<int> edge[10];
    for (auto it : v)
      for (auto to : g[it])
        if (!used[to.second]) edge[to.first].push_back(to.second);
    for (int d = 0; d < 10; ++d) {
      if (edge[d].empty()) continue;
      temp.clear();
      for (auto it : edge[d])
        if (!used[it]) {
          used[it] = 1;
          temp.push_back(it);
          sol[it] = (sol[v.back()] * 10 + d) % (int)(1e9 + 7);
        }
      if (!temp.empty()) bucket.push_back(temp);
    }
  }
  for (int i = 2; i <= n; ++i) cout << sol[i] << '\n';
  return 0;
}
void addEdge(int x, int y, int k) {
  while (k > 9) {
    g[++t].push_back({k % 10, y});
    y = t;
    k /= 10;
  }
  g[x].push_back({k, y});
}
