#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int n, m, s = 0;
cin >>n >>m;
vector <vector <int> > g(n);
for (int i = 0; i < n; ++i) {
int from, to;
cin >>from >>to;
from--; to--;
g[from].push_back(to);
g[to].push_back(from);
}
queue<int> q;
q.push(s);
vector<bool> used(n);
vector<int> d(n), p(n);
used[s] = true;
p[s] = -2;
while (!q.empty()) {
int v = q.front();
q.pop();
for (int i = 0; i<g[v].size(); ++i) {
int to = g[v][i];
if (!used[to]) {
used[to] = true;
q.push(to);
d[to] = d[v] + 1;
p[to] = v;
}
}
}
for (int i = 0; i < n; ++i) {
cout << '\"' << i + 1 << "\" -> \"" << p[i] + 1 << "\"" <<endl;
}
return 0;
}