#include <bits/stdc++.h>
using namespace std;
const int MAXN = 101010;
int deg[MAXN], n, e[MAXN];
vector<pair<int, int> > G[MAXN];
int main() {
  memset(e, -1, sizeof e);
  scanf("%d", &n);
  if (n == 2) {
    puts("0");
    return 0;
  }
  int z = 0;
  for (int i = 1; i < n; ++i) {
    static int u, v;
    scanf("%d%d", &u, &v);
    G[u].emplace_back(v, i - 1);
    G[v].emplace_back(u, i - 1);
    deg[u]++;
    deg[v]++;
  }
  queue<int> q;
  for (int i = 1; i <= n; ++i)
    if (deg[i] == 1) e[G[i][0].second] = z++;
  for (int i = 0; i < n - 1; ++i) {
    if (e[i] == -1) e[i] = z++;
    printf("%d\n", e[i]);
  }
  return 0;
}
