#include <bits/stdc++.h>
const int maxn = 1e5 + 10;
using namespace std;
int a[maxn], d[maxn], u[maxn], v[maxn];
int main() {
  int n, x;
  int i, j;
  cin >> n;
  for (i = 1; i < n; i++) {
    cin >> u[i] >> v[i];
    a[i] = -1;
    d[u[i]]++;
    d[v[i]]++;
  }
  x = -1;
  for (i = 1; i <= n; i++) {
    if (d[i] > 2) {
      for (j = 1; j < n; j++) {
        if (u[j] == i || v[j] == i) {
          a[j] = ++x;
          if (x == 2) break;
        }
      }
      break;
    }
  }
  for (i = 1; i < n; i++)
    if (a[i] == -1) a[i] = ++x;
  for (i = 1; i < n; i++) cout << a[i] << endl;
  return 0;
}
