#include <bits/stdc++.h>
using namespace std;
int num = 1;
void assignWeight(vector<pair<int, int> > adj[], int n, int point) {
  for (int i = 0; i < adj[point].size(); i++) {
    assignWeight(adj, n, adj[point][i].first);
    adj[point][i].second = num;
    num += 1;
  }
  return;
}
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > adj[n + 1];
  int i, j;
  for (i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back({v, 0});
  }
  assignWeight(adj, n, 1);
  for (i = 1; i <= n; i++) {
    for (j = 0; j < adj[i].size(); j++) {
      if (adj[i][j].second == n - 1)
        cout << "0" << endl;
      else
        cout << adj[i][j].second << endl;
    }
  }
}
