#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n;
pair<int, int> edges[maxn];
int deg[maxn], ans[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    deg[u]++, deg[v]++;
    edges[i] = make_pair(u, v);
  }
  int p = -1;
  for (int i = 1; i <= n; i++)
    if (deg[i] >= 3) p = i;
  if (p == -1) {
    for (int i = 0; i < n - 1; i++) cout << i << '\n';
    return 0;
  }
  int rest = 3, cnt1 = 0, cnt2 = n - 2;
  for (int i = 0; i < n - 1; i++) {
    int u = edges[i].first, v = edges[i].second;
    if ((u == p || v == p) && rest) {
      ans[i] = cnt1++;
      rest--;
    } else
      ans[i] = cnt2--;
  }
  for (int i = 0; i < n - 1; i++) cout << ans[i] << '\n';
  return 0;
}
