#include <bits/stdc++.h>
using namespace std;
const int N = 5e+5 + 5;
int end = 2;
vector<int> v[N];
vector<int> g[N];
void dfs(int u, int p, int start, int tmp_end) {
  int len = g[u].size(), cnt = g[u].size();
  if (u != 1) cnt--;
  v[u].emplace_back(start);
  v[u].emplace_back(::end + len);
  ::end = ::end + len;
  for (auto it : g[u]) {
    if (it != p) dfs(it, u, tmp_end + cnt, ::end), cnt--;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    g[x].emplace_back(y);
    g[y].emplace_back(x);
  }
  dfs(1, 0, 1, 1);
  for (int i = 1; i <= n; i++) cout << v[i][0] << " " << v[i][1] << endl;
  return 0;
}
