#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, a, b, p = 0, s = 0;
  cin >> n;
  vector<vector<long long> > g(n);
  vector<long long> ans(n - 1, -1);
  for (long long i = 0; i < n - 1; i++) {
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(i);
    g[b].push_back(i);
  }
  for (long long i = 0; i < n; i++) {
    if (g[i].size() == 1) {
      ans[g[i][0]] = p;
      p++;
    }
  }
  for (long long i = 0; i < n - 1; i++) {
    if (ans[i] == -1) {
      cout << n - 2 - s << "\n";
      s++;
    } else {
      cout << ans[i] << "\n";
    }
  }
}
