#include <bits/stdc++.h>
using namespace std;
const long long mxN = 2e5 + 1;
long long n;
vector<long long> adj[mxN];
long long ans[mxN];
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  memset(ans, -1, sizeof(ans));
  cin >> n;
  for (long long i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    --a, --b;
    adj[a].push_back(i);
    adj[b].push_back(i);
  }
  long long mn = 0;
  for (long long i = 0; i <= n - 1; i++) {
    if (adj[i].size() > 2) {
      ans[adj[i][0]] = 0;
      ans[adj[i][1]] = 1;
      ans[adj[i][2]] = 2;
      mn = 3;
      break;
    }
  }
  for (long long i = 0; i < n - 1; i++) {
    if (ans[i] == -1) ans[i] = mn++;
  }
  for (long long i = 0; i < n - 1; i++) {
    cout << ans[i] << "\n";
  }
  return 0;
}
