#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<vector<int> > v(n);
  vector<pair<int, int> > p(n - 1);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    p[i] = make_pair(x - 1, y - 1);
    v[x - 1].push_back(y - 1);
    v[y - 1].push_back(x - 1);
  }
  int i;
  for (i = 0; i < n; i++) {
    if (v[i].size() == 1) break;
  }
  i = v[i][0];
  while (v[i].size() == 2) {
    if (i != v[i][0])
      i = v[i][0];
    else
      i = v[i][1];
  }
  if (v[i].size() == 1) {
    for (i = 0; i < n - 1; i++) cout << i << endl;
  } else {
    int x = v[i][0], y = v[i][1], z = v[i][2];
    int m = 2, k = 0;
    for (int j = 0; j < n - 1; j++) {
      if (p[j].first == i &&
          (p[j].second == x || p[j].second == y || p[j].second == z)) {
        cout << k << endl;
        k++;
      } else {
        cout << m << endl;
        m++;
      }
    }
  }
}
