#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v[n + 1];
  vector<pair<int, int>> u;
  int a, b;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    u.push_back({a, b});
    v[a].push_back(b);
    v[b].push_back(a);
  }
  int c = n - 2, f = -1, k = 0;
  for (int i = 1; i <= n; i++) {
    if (v[i].size() >= 3) {
      f = i;
      break;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    pair<int, int> p = u[i];
    if (f != -1 && (p.first == f || p.second == f)) {
      cout << k << endl;
      k++;
    } else {
      cout << c << endl;
      c--;
    }
  }
}
