#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, lg = 20, N = 1e5 + 5;
int ans[N];
bool vis[N];
vector<pair<int, int> > g[N];
struct node {
  node *ch[11];
  node *sp[lg];
  int val, lvl, last;
  node() {
    memset(ch, 0, sizeof ch);
    memset(sp, 0, sizeof sp);
    val = lvl = last = 0;
  }
};
struct cmp {
  bool operator()(const pair<node *, int> a, const pair<node *, int> b) const {
    if (b.first->lvl != a.first->lvl) return a.first->lvl < b.first->lvl;
    node *u = (node *)b.first;
    node *v = (node *)a.first;
    for (int i = lg - 1; i >= 0; i--) {
      if (u->sp[i] != v->sp[i]) {
        u = u->sp[i];
        v = v->sp[i];
      }
    }
    if (v->last != u->last) return v->last < u->last;
    return a.second < b.second;
  }
};
vector<int> digits[N];
void build() {
  for (int i = 1; i < N; i++) {
    int j = i;
    while (j) digits[i].push_back(j % 10), j /= 10;
    reverse(digits[i].begin(), digits[i].end());
  }
}
void build(node *a) {
  for (int i = 1; i < lg; i++) {
    a->sp[i] = a->sp[i - 1]->sp[i - 1];
  }
}
void dij() {
  node *root = new node();
  root->sp[0] = root;
  build(root);
  set<pair<node *, int>, cmp> st;
  st.insert({root, 1});
  while (st.size()) {
    node *cur = (*st.begin()).first;
    int temp = (*st.begin()).second;
    st.erase(st.begin());
    if (vis[temp] == 0) {
      vis[temp] = 1;
      ans[temp] = cur->val;
    } else
      continue;
    for (int i = 0; i < g[temp].size(); i++) {
      int v = g[temp][i].first;
      int cost = g[temp][i].second;
      node *temp = cur;
      for (auto dig : digits[cost]) {
        if (!temp->ch[dig]) {
          temp->ch[dig] = new node();
          temp->ch[dig]->lvl = temp->lvl + 1;
          temp->ch[dig]->val = ((temp->val * 1ll * 10) % mod + dig) % mod;
          temp->ch[dig]->sp[0] = temp;
          temp->ch[dig]->last = dig;
          build(temp->ch[dig]);
        }
        temp = temp->ch[dig];
      }
      st.insert({temp, v});
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  build();
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back({v, i});
    g[v].push_back({u, i});
  }
  dij();
  for (int i = 2; i <= n; i++) cout << ans[i] << '\n';
  return 0;
}
