#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(false);
  long long int i, n, j, k, l;
  cin >> n;
  vector<vector<int>> a(n + 1);
  map<pair<int, int>, int> b;
  for (i = 0; i < n - 1; i++) {
    cin >> j >> k;
    a[j].push_back(k);
    a[k].push_back(j);
    if (k > j) swap(k, j);
    b[make_pair(k, j)] = i;
  }
  j = 0;
  queue<int> q;
  q.push(1);
  vector<int> c(n + 1, 0), d(n);
  while (q.size()) {
    k = q.front();
    c[k] = 1;
    q.pop();
    for (l = 0; l < a[k].size(); l++) {
      if (c[a[k][l]] == 0) {
        q.push(a[k][l]);
        if (k < a[k][l]) {
          d[b[make_pair(k, a[k][l])]] = j++;
        } else {
          d[b[make_pair(a[k][l], k)]] = j++;
        }
      }
    }
  }
  for (i = 0; i < n - 1; i++) cout << d[i] << " ";
}
