#include <bits/stdc++.h>
using namespace std;
const int maxn = 1001001;
int n;
vector<int> g[maxn];
int N;
int nex[maxn], prv[maxn];
int l[maxn], r[maxn];
int X[maxn];
void insert(int first, int me, int second) {
  nex[first] = me;
  nex[me] = second;
  prv[second] = me;
  prv[me] = first;
}
void dfs(int v, int par = -1) {
  for (int u : g[v])
    if (u != par) {
      l[u] = N++;
      insert(prv[l[v]], l[u], l[v]);
      r[u] = N++;
      insert(l[v], r[u], nex[l[v]]);
      dfs(u, v);
    }
}
void solve() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int v, u;
    cin >> v >> u;
    v--, u--;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  int head = 0;
  int tail = 1;
  nex[head] = tail;
  prv[tail] = head;
  N = 2;
  l[0] = N++;
  insert(head, l[0], tail);
  r[0] = N++;
  insert(l[0], r[0], tail);
  dfs(0);
  for (int v = head, x = 0; v != tail; v = nex[v]) X[v] = x++;
  for (int i = 0; i < n; i++) cout << X[l[i]] << " " << X[r[i]] << "\n";
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  t = 1;
  while (t--) solve();
  return 0;
}
