#include <bits/stdc++.h>
using namespace std;
const long long MAX1 = 1e5 + 7, MOD = 998244353;
long long q, n, x, y, e[MAX1][2], p[MAX1], cnt1, cnt2, ans[MAX1];
set<long long> st;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    cin >> x >> y;
    e[i][0] = x;
    e[i][1] = y;
    p[x]++;
    p[y]++;
  }
  cnt2 = n - 2;
  for (int i = 0; i < n - 1; ++i) {
    if (p[e[i][0]] == 1 || p[e[i][1]] == 1) {
      ans[i] = cnt1++;
    } else {
      ans[i] = cnt2--;
    }
  }
  for (int i = 0; i < n - 1; ++i) cout << ans[i] << '\n';
  return 0;
}
