#include <bits/stdc++.h>
using namespace std;
vector<int> g[500001];
int curmax;
pair<int, int> ans[500001];
void dfs(int v, int p, int h) {
  int cnt = 1;
  for (int i : g[v]) {
    if (i == p) continue;
    curmax += g[i].size();
    ans[i] = {h - cnt, curmax};
    dfs(i, v, curmax);
    cnt++;
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  ans[1] = {1, 2 + g[1].size()};
  curmax = 2 + g[1].size();
  dfs(1, 1, curmax);
  for (int i = 1; i <= n; i++) {
    cout << ans[i].first << ' ' << ans[i].second << '\n';
  }
  return 0;
}
