#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000000 + 7;
const int maxn = 500000 + 5;
long long pow_mod(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
vector<int> g[maxn];
vector<int> t;
void dfs(int u, int p) {
  for (int v : g[u]) {
    if (v != p) t.push_back(v);
  }
  t.push_back(u);
  for (int i = g[u].size() - 1; i >= 0; i--) {
    int v = g[u][i];
    if (v != p) dfs(v, u);
  }
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1, u, v; i < n; i++) {
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  t.push_back(1);
  dfs(1, 0);
  vector<pair<int, int>> res(n + 1);
  for (int i = 0; i < t.size(); i++)
    (res[t[i]].first == 0 ? res[t[i]].first : res[t[i]].second) = i + 1;
  for (int i = 1; i <= n; i++)
    cout << res[i].first << " " << res[i].second << endl;
  return 0;
}
