#include <bits/stdc++.h>
using namespace std;
const int mod1 = 998244353, mod = 1e9 + 7;
const int MAXN = 5e5 + 6, MAXM = 2e5 + 5;
const int inf = 2e9;
const long long linf = 1e18;
int pos[2 * MAXN], n, x = 0;
vector<int> adj[MAXN], ans[MAXN];
void dfs(int u, int p) {
  for (int v : adj[u])
    if (p != v) pos[++x] = v;
  pos[++x] = u;
  reverse(adj[u].begin(), adj[u].end());
  for (int v : adj[u]) {
    if (p != v) dfs(v, u);
  }
}
void Solve() {
  cin >> n;
  for (int i = 1, u, v; i < n; i++) {
    cin >> u >> v;
    adj[u].emplace_back(v);
    adj[v].emplace_back(u);
  }
  pos[++x] = 1;
  dfs(1, -1);
  for (int i = 1; i <= 2 * n; i++) {
    ans[pos[i]].emplace_back(i);
  }
  cout << '\n';
  for (int i = 1; i <= n; i++) {
    for (auto v : ans[i]) cout << v << ' ';
    cout << '\n';
  }
}
signed main() {
  if (fopen(""
            ".inp",
            "r")) {
    freopen(
        ""
        ".inp",
        "r", stdin);
    freopen(
        ""
        ".out",
        "w", stdout);
  };
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int TC = 1;
  while (TC--) Solve();
  return 0;
}
