#include <bits/stdc++.h>
using namespace std;
long long int cnt;
int vis[5000004];
vector<pair<int, int> > v[5000004];
long long int dst[5000004];
int bfs() {
  queue<pair<int, int> > que;
  long long int ct = 0;
  que.push(make_pair(1, ct));
  ct++;
  vis[1] = 1;
  while (!que.empty()) {
    vector<long long int> vc;
    int x = que.front().second;
    while (!que.empty() && que.front().second == x) {
      vc.push_back(que.front().first);
      que.pop();
    }
    vector<pair<int, int> > vec[10];
    for (int i = 0; i < vc.size(); i++) {
      for (int j = 0; j < v[vc[i]].size(); j++) {
        vec[v[vc[i]][j].first].push_back(make_pair(v[vc[i]][j].second, vc[i]));
      }
    }
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < vec[i].size(); j++) {
        if (vis[vec[i][j].first] == 1) continue;
        vis[vec[i][j].first] = 1;
        dst[vec[i][j].first] =
            ((dst[vec[i][j].second] * 10) % 1000000007 + i) % 1000000007;
        que.push(make_pair(vec[i][j].first, ct));
      }
      ct++;
    }
  }
  return 0;
}
int main() {
  int n, m;
  cin >> n >> m;
  cnt = n + 1;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    int x = i;
    vector<int> vc;
    while (x != 0) {
      vc.push_back(x % 10);
      x = x / 10;
    }
    int pr = a;
    for (int j = vc.size() - 1; j > 0; j--) {
      v[pr].push_back(make_pair(vc[j], cnt));
      pr = cnt;
      cnt++;
    }
    v[pr].push_back(make_pair(vc[0], b));
    pr = b;
    for (int j = vc.size() - 1; j > 0; j--) {
      v[pr].push_back(make_pair(vc[j], cnt));
      pr = cnt;
      cnt++;
    }
    v[pr].push_back(make_pair(vc[0], a));
  }
  bfs();
  for (int i = 2; i <= n; i++) cout << dst[i] << endl;
  return 0;
}
