#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
struct node {
  int id, type;
  node* nxt = nullptr;
  node(){};
  node(int id, int type) : id(id), type(type){};
};
int n;
node* head[N];
node* tail[N];
vector<int> adj[N];
pair<int, int> res[N];
void dfs(int u, int p) {
  vector<node*> p1, p2, p3;
  for (int v : adj[u]) {
    if (v == p) {
      continue;
    }
    dfs(v, u);
    p1.push_back(head[v]);
    p2.push_back(head[v]->nxt);
    p3.push_back(tail[v]);
  }
  head[u] = new node(u, 0);
  tail[u] = new node(u, 1);
  node* cur = head[u];
  int sz = p1.size();
  for (int i = 0; i < sz; ++i) {
    cur->nxt = p1[i];
    cur = p1[i];
  }
  cur->nxt = tail[u];
  cur = tail[u];
  for (int i = sz - 1; i >= 0; --i) {
    cur->nxt = p2[i];
    cur = p3[i];
  }
  tail[u] = cur;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1, u, v; i < n; ++i) {
    cin >> u >> v;
    adj[u].emplace_back(v);
    adj[v].emplace_back(u);
  }
  dfs(1, -1);
  node* cur = head[1];
  for (int i = 1; i <= 2 * n; ++i) {
    if (cur->type == 0) {
      res[cur->id].first = i;
    } else {
      res[cur->id].second = i;
    }
    cur = cur->nxt;
  }
  for (int i = 1; i <= n; ++i) {
    cout << res[i].first << " " << res[i].second << '\n';
  }
  return 0;
}
