#include <bits/stdc++.h>
using namespace std;
vector<int> v[100100];
int ans[100100];
int main() {
  int n, a, b;
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> a >> b;
    v[a].push_back(i);
    v[b].push_back(i);
    ans[i] = -1;
  }
  pair<int, int> mx(0, 0);
  for (int i = 1; i <= (int)(n); ++i) {
    mx = max(mx, make_pair((int)v[i].size(), i));
  }
  int curr = 0;
  for (int i : v[mx.second]) {
    ans[i] = curr++;
  }
  for (int i = 1; i < n; i++) {
    if (ans[i] == -1) ans[i] = curr++;
    cout << ans[i] << endl;
  }
}
