#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, u, v;
  cin >> n;
  int edges[100001] = {0};
  vector<int> adj[n];
  vector<pair<int, int>> ed;
  for (i = 0; i < n - 1; i++) {
    cin >> u >> v;
    edges[u - 1]++;
    edges[v - 1]++;
    adj[u - 1].push_back(v - 1);
    adj[v - 1].push_back(u - 1);
    ed.push_back(make_pair(u - 1, v - 1));
  }
  int nx = -1;
  for (i = 0; i < 100001; i++) {
    if (edges[i] >= 3) {
      nx = i;
      break;
    }
  }
  if (nx != -1) {
    int node1 = adj[nx][0];
    int node2 = adj[nx][1];
    int node3 = adj[nx][2];
    int cur = 0;
    int val = 3;
    for (i = 0; i < n - 1; i++) {
      if ((ed[i].first == nx &&
           (ed[i].second == node1 || ed[i].second == node2 ||
            ed[i].second == node3)) ||
          (ed[i].second == nx &&
           (ed[i].first == node1 || ed[i].first == node2 ||
            ed[i].first == node3))) {
        cout << cur << endl;
        cur++;
      } else {
        cout << val << endl;
        val++;
      }
    }
  } else {
    for (i = 0; i < n - 1; i++) {
      cout << i << endl;
    }
  }
  return 0;
}
