#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int M = 1e5 + 10;
int n, m, vis[M * 12], ans[M * 12], tot;
vector<int> vt[10][M * 12], tmp;
vector<vector<int> > now, nxt;
void add(int x, int y, int id) {
  while (id / 10) vt[id % 10][++tot].push_back(y), y = tot, id /= 10;
  vt[id][x].push_back(y);
}
void bfs() {
  vis[1] = 1;
  now.push_back(vector<int>(1, 1));
  while (!now.empty()) {
    for (int p = 0; p < now.size(); p++) {
      vector<int> a = now[p];
      for (int w = 0; w < 10; w++) {
        tmp.clear();
        for (int i = 0; i < a.size(); i++) {
          int x = a[i];
          for (int j = 0; j < vt[w][x].size(); j++) {
            int y = vt[w][x][j];
            if (vis[y]) continue;
            vis[y] = 1;
            ans[y] = (10LL * ans[x] % mod + w) % mod;
            tmp.push_back(y);
          }
        }
        if (tmp.size()) nxt.push_back(tmp);
      }
    }
    now = nxt;
    nxt.clear();
  }
}
int main(int argc, char const *argv[]) {
  scanf("%d%d", &n, &m);
  tot = n;
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y, i);
    add(y, x, i);
  }
  bfs();
  for (int i = 2; i <= n; i++) printf("%d\n", ans[i]);
  return 0;
}
