#include <bits/stdc++.h>
using namespace std;
int T;
int n;
vector<int> edg[100010];
int main() {
  int from, to;
  scanf("%d", &n);
  int ans = -1;
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &from, &to);
    if (ans == -1) {
      edg[from].push_back(i);
      edg[to].push_back(i);
      if (edg[from].size() >= 3) ans = from;
      if (edg[to].size() >= 3) ans = to;
    }
  }
  int cnt1 = 0, cnt2 = (ans == -1 ? 0 : 3);
  for (int i = 1; i <= n - 1; i++)
    if (ans != -1 && (i == edg[ans][0] || i == edg[ans][1] || i == edg[ans][2]))
      printf("%d\n", cnt1++);
    else
      printf("%d\n", cnt2++);
  return 0;
}
