#include <bits/stdc++.h>
using namespace std;
void printvector(std::vector<long long> v) {
  for (long long i = 0; i < v.size(); ++i) {
    cout << v[i] << " ";
  }
  cout << "" << endl;
}
void printarray(long long a[], long long n) {
  for (long long i = 0; i < n; ++i) {
    cout << a[i] << " ";
  }
  cout << "" << endl;
}
const long long N = 5 * 1e5;
pair<long long, long long> ans[N];
std::vector<long long> adj[N];
long long n;
std::vector<long long> v;
long long in = 0;
void dfs(long long s, long long z, bool visited[]) {
  std::vector<long long> next;
  ans[s].first = z;
  visited[s] = true;
  for (auto it : adj[s]) {
    if (!visited[it]) {
      next.push_back(v[in]);
      in++;
    }
  }
  ans[s].second = v[in];
  in++;
  for (auto it : adj[s]) {
    if (!visited[it]) {
      dfs(it, next.back(), visited);
      next.pop_back();
    }
  }
}
void solve() {
  cin >> n;
  for (long long i = 0; i < 2 * n; i++) {
    v.push_back(i + 1);
  }
  for (long long i = 0; i < n - 1; i++) {
    long long u, z;
    cin >> u >> z;
    u--;
    z--;
    adj[u].push_back(z);
    adj[z].push_back(u);
  }
  bool visited[n];
  memset(visited, false, sizeof(visited));
  in = 1;
  dfs(0, 1, visited);
  for (long long i = 0; i < n; i++) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
