#include <bits/stdc++.h>
using namespace std;
int n, x, y, i, siz[500005], seq[1000005], e[2][500005];
vector<int> s[500005];
void dfs(int p, int f) {
  int i, v;
  siz[p] = 1;
  for (i = 0; i < s[p].size(); i++) {
    v = s[p][i];
    if (v == f) continue;
    dfs(v, p);
    siz[p] += siz[v];
  }
}
void dfs2(int l, int r, int p, int f) {
  if (l == r) {
    seq[l] = p;
    return;
  }
  int i, v, pre;
  pre = l - 1;
  for (i = 0; i < s[p].size(); i++) {
    v = s[p][i];
    if (v == f) continue;
    dfs2(pre + 1, pre + 2 * siz[v] - 1, v, p);
    pre += 2 * siz[v] - 1;
  }
  seq[++pre] = p;
  for (i = s[p].size() - 1; i >= 0; i--) {
    v = s[p][i];
    if (v == f) continue;
    seq[++pre] = v;
  }
}
int main() {
  scanf("%d", &n);
  for (i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    s[x].push_back(y);
    s[y].push_back(x);
  }
  dfs(1, 0);
  seq[2 * n] = 1;
  dfs2(1, 2 * n - 1, 1, 0);
  for (i = 1; i <= 2 * n; i++) {
    if (e[0][seq[i]] == 0)
      e[0][seq[i]] = i;
    else
      e[1][seq[i]] = i;
  }
  for (i = 1; i <= n; i++) printf("%d %d\n", e[0][i], e[1][i]);
  return 0;
}
