#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
bool mark[N];
vector<int> e[N];
pair<int, int> rep[N];
int lf;
void dfs(int n, int l, int r) {
  mark[n] = 1;
  rep[n] = make_pair(l, r);
  r = l;
  for (int y : e[n]) {
    if (mark[y]) continue;
    int cnt = 0;
    for (int z : e[y]) cnt += !mark[z];
    lf -= cnt + 1;
    dfs(y, lf, ++r);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    cin >> x >> y;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  dfs(1, lf = N, N + e[1].size() + 1);
  int dd = N;
  for (int i = 1; i <= n; ++i) dd = min(dd, rep[i].first);
  for (int i = 1; i <= n; ++i) {
    rep[i].first -= dd - 1;
    rep[i].second -= dd - 1;
  }
  for (int i = 1; i <= n; ++i)
    cout << rep[i].first << " " << rep[i].second << endl;
  return 0;
}
