#include <bits/stdc++.h>
using namespace std;
void solve() {}
int main() {
  int n;
  cin >> n;
  vector<int> v(n, 0);
  vector<int> x(n, 0);
  vector<int> y(n, 0);
  for (int i = 0; i < n - 1; i++) {
    cin >> x[i] >> y[i];
    v[x[i] - 1]++;
    v[y[i] - 1]++;
  }
  int q = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] >= 3) {
      q = i + 1;
    }
  }
  if (q == 0) {
    for (int i = 0; i < n - 1; i++) {
      cout << i << endl;
    }
  } else {
    int j = 3;
    int jj = 0;
    for (int i = 0; i < n - 1; i++) {
      if (jj >= 3 || (y[i] != q && x[i] != q)) {
        cout << j << endl;
        j++;
      } else {
        cout << jj << endl;
        jj++;
      }
    }
  }
  return 0;
}
