#include <bits/stdc++.h>
int N;
std::vector<std::vector<int>> tree;
bool placed = false;
int ctr = 0;
std::vector<int> p_num, par;
std::map<std::pair<int, int>, int> e_idx;
void place_zero(int n, int p) {
  par[n] = p;
  if (tree[n].size() > 2 && !placed) {
    placed = true;
    if (n == 0) {
      p_num[tree[0][0]] = 0;
      p_num[tree[0][1]] = 1;
      p_num[tree[0][2]] = 2;
    } else {
      p_num[n] = 0;
      int ch_placed = 0;
      for (int i = 0; i < tree[n].size() || ch_placed < 2; i++) {
        if (tree[n][i] == p) continue;
        p_num[tree[n][i]] = ch_placed + 1;
        ch_placed++;
      }
    }
    ctr = 3;
  }
  for (int ch : tree[n])
    if (ch != p) place_zero(ch, n);
}
void place_normal(int n, int p) {
  if (n != 0 && p_num[n] == -1) p_num[n] = ctr++;
  for (int ch : tree[n])
    if (ch != p) place_normal(ch, n);
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cin >> N;
  tree.resize(N);
  par.resize(N);
  p_num.resize(N, -1);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    std::cin >> a >> b;
    a--;
    b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
    e_idx[{a, b}] = i;
    e_idx[{b, a}] = i;
  }
  place_zero(0, -1);
  place_normal(0, -1);
  std::vector<int> res(N - 1);
  for (int i = 1; i < N; i++) res[e_idx[{i, par[i]}]] = p_num[i];
  for (int i = 0; i < N - 1; i++) std::cout << res[i] << "\n";
}
