#include <bits/stdc++.h>
using namespace std;
int cnt[200005];
vector<int> ans(200005);
int main() {
  int n;
  cin >> n;
  int my = 0;
  vector<int> x;
  vector<int> y;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    cnt[a]++, cnt[b]++;
    x.push_back(a), y.push_back(b);
  }
  for (int i = 1; i <= n; i++) {
    if (cnt[i] >= cnt[my]) my = i;
  }
  int counter = 0;
  for (int i = 0; i < n - 1; i++) {
    if (x[i] == my || y[i] == my) {
      ans[i] = counter;
      counter++;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    if (ans[i] == 0 && (x[i] != my && y[i] != my)) {
      ans[i] = counter;
      counter++;
    }
  }
  for (int i = 0; i < n - 1; i++) cout << ans[i] << endl;
  return 0;
}
