#include <bits/stdc++.h>
using namespace std;
int n;
int ans[100005];
vector<pair<int, int> > edges;
int child[100005];
int parent[100005];
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  memset(ans, -1, sizeof(ans));
  cin >> n;
  int u, v;
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v;
    edges.push_back({u, v});
    child[u]++;
    parent[v]++;
  }
  int num = 0;
  for (int i = 0; i < n - 1; i++) {
    u = edges[i].first;
    v = edges[i].second;
    if (child[v] == 0) {
      ans[i] = num++;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    u = edges[i].first;
    v = edges[i].second;
    if (ans[i] != -1) continue;
    if (parent[u] == 0 && child[v] > 0) {
      ans[i] = num++;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    if (ans[i] != -1) continue;
    ans[i] = num++;
  }
  for (int i = 0; i < n - 1; i++) cout << ans[i] << '\n';
  return 0;
}
