#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200009;
const long long MOD = 1e9 + 7;
class {
 public:
  int n, m;
  vector<int> V[877780 + 99][10];
  long long ans[877780 + 99];
  bool vis[877780 + 99];
  void solve() {
    cin >> n >> m;
    int M = n;
    for (int i = 1; i <= m; ++i) {
      int u, v;
      cin >> u >> v;
      string s = to_string(i);
      int pre = u;
      for (int j = 0; j < s.length(); ++j) {
        if (j == s.length() - 1)
          V[pre][s[j] - '0'].push_back(v);
        else
          V[pre][s[j] - '0'].push_back(++M);
        pre = M;
      }
      pre = v;
      for (int j = 0; j < s.length(); ++j) {
        if (j == s.length() - 1)
          V[pre][s[j] - '0'].push_back(u);
        else
          V[pre][s[j] - '0'].push_back(++M);
        pre = M;
      }
    }
    ans[1] = 0;
    vector<int> Q[2], equ[2];
    vis[1] = 1;
    int cur = 0;
    Q[cur].push_back(1);
    equ[cur].push_back(1);
    while (Q[cur].size()) {
      Q[cur ^ 1].clear();
      equ[cur ^ 1].clear();
      assert(Q[cur].size() == equ[cur].size());
      int pequ = 0;
      for (int i = 0; i < Q[cur].size();) {
        int j = i;
        while (i < Q[cur].size() && equ[cur][j] == equ[cur][i]) ++i;
        for (int num = 0; num <= 9; num++) {
          bool has = 0;
          for (int ii = j; ii < i; ++ii) {
            int u = Q[cur][ii];
            for (int v : V[u][num]) {
              if (!vis[v]) {
                ans[v] = (ans[u] * 10 + num) % MOD;
                vis[v] = 1;
                Q[cur ^ 1].push_back(v);
                equ[cur ^ 1].push_back(pequ);
                has = 1;
              }
            }
          }
          if (has) {
            pequ ^= 1;
          }
        }
      }
      cur ^= 1;
    }
    for (int i = 2; i <= n; ++i) cout << ans[i] << "\n";
  }
} NSPACE;
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}
