#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long N = 1e6 + 10;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
const long long eps = 1e-9;
const char spc = 29;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
using namespace std;
long long n;
vector<long long> g[N];
vector<long long> order;
void dfs(long long v, long long p) {
  vector<long long> nxt;
  for (auto u : g[v])
    if (u != p) {
      order.push_back(u);
      nxt.push_back(u);
    }
  order.push_back(v);
  reverse(nxt.begin(), nxt.end());
  for (auto u : nxt) dfs(u, v);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 0; i < n - 1; ++i) {
    long long v, u;
    cin >> v >> u;
    --v;
    --u;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  order.push_back(0);
  dfs(0, 0);
  vector<pair<long long, long long> > ans(n);
  set<long long> st;
  long long cur = 1;
  for (auto it : order)
    if (st.find(it) == st.end()) {
      st.insert(it);
      ans[it].first = cur++;
    } else
      ans[it].second = cur++;
  for (auto &p : ans) cout << p.first << " " << p.second << "\n";
}
