#include <bits/stdc++.h>
using namespace std;
int n, root = -1, nextnum = 3;
vector<vector<int>> edges[100005];
int order[100005];
int main() {
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    int a, b;
    cin >> a >> b;
    edges[a].push_back({b, i});
    edges[b].push_back({a, i});
  }
  for (int i = 1; i <= n; i++) {
    if (edges[i].size() > 2) {
      root = i;
      break;
    }
  }
  if (root == -1) {
    for (int i = 0; i <= n - 2; i++) {
      cout << i << "\n";
    }
  } else {
    for (int i = 1; i <= n - 1; i++) {
      order[i] = -1;
    }
    order[edges[root][0][1]] = 0;
    order[edges[root][1][1]] = 1;
    order[edges[root][2][1]] = 2;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < edges[i].size(); j++) {
        if (order[edges[i][j][1]] == -1) {
          order[edges[i][j][1]] = nextnum;
          nextnum++;
        }
      }
    }
    for (int i = 1; i <= n - 1; i++) {
      cout << order[i] << "\n";
    }
  }
  return 0;
}
