#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 17;
list<int> ls;
vector<int> out[maxn];
int n;
vector<int> g[maxn];
void dfs(int v = 0, int p = 0, list<int>::iterator w = ls.begin()) {
  for (auto u : g[v])
    if (u != p) {
      ls.insert(next(w), u);
      dfs(u, v, ls.insert(w, u));
    }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int v, u;
    cin >> v >> u;
    v--, u--;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  ls = {0, 0};
  dfs();
  for (int i = 0; i < 2 * n; i++) {
    static auto it = ls.begin();
    out[*it++].push_back(i);
  }
  for (int i = 0; i < n; i++)
    cout << out[i][0] + 1 << ' ' << out[i][1] + 1 << '\n';
}
