#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k = 0;
  cin >> n;
  vector<long long> v[n + 1];
  map<pair<long long, long long>, long long> m;
  long long a[n], b[n];
  for (long long i = 0; i < n - 1; i++) {
    cin >> a[i] >> b[i];
    v[a[i]].push_back(b[i]);
    v[b[i]].push_back(a[i]);
    m[{a[i], b[i]}] = -1;
    m[{b[i], a[i]}] = -1;
  }
  if (n == 2) {
    cout << "0";
    return 0;
  }
  for (long long i = 1; i < n + 1; i++) {
    if (v[i].size() == 1) {
      m[{i, v[i][0]}] = k;
      m[{v[i][0], i}] = k;
      k++;
    }
  }
  for (long long i = 0; i < n - 1; i++) {
    if (m[{a[i], b[i]}] == -1) {
      cout << k << endl;
      k++;
    } else
      cout << m[{a[i], b[i]}] << endl;
  }
}
