#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
long long n, a, b, ans[N];
vector<long long> v[N];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  cin >> n;
  for (long long i = 1; i < n; i++) {
    cin >> a >> b;
    v[a].push_back(i);
    v[b].push_back(i);
    ans[i] = -1;
  }
  pair<long long, long long> m(0, 0);
  for (long long i = 1; i <= n; i++) {
    m = max(m, {(long long)v[i].size(), i});
  }
  long long c = 0;
  for (auto it : v[m.second]) {
    ans[it] = c++;
  }
  for (long long i = 1; i < n; i++) {
    if (ans[i] == -1) ans[i] = c++;
    cout << ans[i] << "\n";
  }
  return 0;
}
