#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[100005];
void solve() {
  long long n;
  cin >> n;
  long long ans[n + 1];
  ans[n] = -1;
  ans[n - 1] = -1;
  for (long long i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
    ans[i] = -1;
  }
  long long cur = 0;
  pair<long long, long long> maxp = {0, 0};
  for (long long i = 1; i <= n - 1; i++) {
    maxp = max(maxp, {adj[i].size(), i});
  }
  for (long long i : adj[maxp.second]) {
    ans[i] = cur++;
  }
  for (long long i = 1; i <= n - 1; i++) {
    if (ans[i] == -1) ans[i] = cur++;
    cout << ans[i] << "\n";
  }
}
int32_t main() {
  long long tc = 1;
  while (tc--) solve();
}
