#include <bits/stdc++.h>
using namespace std;
long long arr[100007];
int main() {
  long long n, x, y, ans = 0, rev;
  cin >> n;
  rev = n - 2;
  vector<long long> X, Y, ANS;
  for (long long i = 0; i < n - 1; i++) {
    cin >> x >> y;
    arr[x]++;
    arr[y]++;
    X.push_back(x);
    Y.push_back(y);
  }
  for (long long i = 0; i < n - 1; i++) {
    if (arr[X[i]] == 1 || arr[Y[i]] == 1)
      cout << ans++ << endl;
    else
      cout << rev-- << endl;
  }
  return 0;
}
