#include <bits/stdc++.h>
using namespace std;
int const MAXN = 2e6 + 9;
vector<vector<int>> g;
vector<int> out[MAXN];
int cur;
void dfs(int node, int par) {
  for (auto child : g[node]) {
    if (child == par) continue;
    out[child].push_back(++cur);
  }
  out[node].push_back(++cur);
  for (int i = (int)g[node].size() - 1; i >= 0; i--) {
    int child = g[node][i];
    if (child == par) continue;
    dfs(child, node);
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  g.resize(n + 1);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  cur = 1;
  out[1].push_back(cur);
  dfs(1, 1);
  for (int i = 1; i <= n; i++) {
    for (auto x : out[i]) cout << x << ' ';
    cout << '\n';
  }
}
