#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const long long mod = 1e9 + 7;
int bsize = 400;
int n, m;
vector<pair<int, int>> vect[maxn];
struct node {
  long long acval;
  string tval;
  vector<int> hval;
  int sz;
} nd[maxn];
int pos[maxn];
struct cmp {
  bool operator()(int a, int b) {
    if (nd[a].sz < nd[b].sz) return true;
    if (nd[a].sz > nd[b].sz) return false;
    for (int i = 0; i < nd[a].hval.size(); i++) {
      if (nd[a].hval[i] < nd[b].hval[i]) return true;
      if (nd[a].hval[i] > nd[b].hval[i]) return false;
    }
    if (nd[a].tval < nd[b].tval) return true;
    if (nd[a].tval > nd[b].tval) return false;
    return a < b;
    return false;
  }
};
bool cmpf(int a, int b) {
  if (nd[a].sz < nd[b].sz) return true;
  if (nd[a].sz > nd[b].sz) return false;
  for (int i = 0; i < nd[a].hval.size(); i++) {
    if (nd[a].hval[i] < nd[b].hval[i]) return true;
    if (nd[a].hval[i] > nd[b].hval[i]) return false;
  }
  if (nd[a].tval < nd[b].tval) return true;
  if (nd[a].tval > nd[b].tval) return false;
  return false;
}
set<int, cmp> st;
void rehash() {
  vector<pair<string, int>> v;
  for (set<int>::iterator it = st.begin(); it != st.end(); it++) {
    int id = (*it);
    v.push_back({nd[id].tval.substr(0, bsize), id});
  }
  sort(v.begin(), v.end());
  int cnt = 1;
  nd[v[0].second].tval.erase(0, bsize);
  nd[v[0].second].hval.push_back(cnt);
  for (int i = 1; i < v.size(); i++) {
    if (v[i].first != v[i - 1].first) cnt++;
    nd[v[i].second].tval.erase(0, bsize);
    nd[v[i].second].hval.push_back(cnt);
  }
}
int ats(int x, int w) {
  int niz[6];
  int br = 0;
  while (w) {
    niz[br++] = w % 10;
    w /= 10;
  }
  int ret = br;
  while (br--) {
    nd[x].tval.push_back(niz[br] + '0');
    nd[x].sz++;
    nd[x].acval *= 10;
    nd[x].acval += niz[br];
    nd[x].acval %= mod;
  }
  return ret;
}
void efs(int x, int br, long long val) {
  nd[x].acval = val;
  for (int i = 1; i <= br; i++) {
    nd[x].sz--;
    nd[x].tval.pop_back();
  }
}
void go() {
  memset(pos, 0, sizeof(pos));
  int x = 1;
  st.insert(x);
  pos[x] = 1;
  while (st.size()) {
    x = (*st.begin());
    if (nd[x].tval.size() > bsize) rehash();
    pos[x] = 1;
    st.erase(st.begin());
    for (int i = 0; i < vect[x].size(); i++) {
      int id = vect[x][i].first;
      int w = vect[x][i].second;
      if (pos[id]) continue;
      if (nd[id].sz == 0) {
        st.erase(id);
        nd[id] = nd[x];
        ats(id, w);
        st.insert(id);
      } else {
        long long pom2 = nd[x].acval;
        int pom = ats(x, w);
        if (cmpf(x, id)) {
          st.erase(id);
          nd[id] = nd[x];
          st.insert(id);
        }
        efs(x, pom, pom2);
      }
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    vect[u].push_back({v, i});
    vect[v].push_back({u, i});
  }
  go();
  for (int i = 2; i <= n; i++) {
    printf("%lld\n", nd[i].acval);
  }
  return 0;
}
