#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
int main() {
  int n;
  cin >> n;
  vector<vector<ii>> tree(n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    tree[u].push_back({v, i});
    tree[v].push_back({u, i});
  }
  queue<ii> q;
  for (int i = 0; i < n; ++i) {
    if (tree[i].size() == 1) {
      q.push(tree[i][0]);
    }
  }
  vector<int> ans(n - 1, -1);
  int cur_i = 0;
  while (!q.empty()) {
    int u = q.front().first;
    int i = q.front().second;
    q.pop();
    if (ans[i] != -1) {
      continue;
    }
    ans[i] = cur_i++;
    for (const auto& e : tree[i]) {
      q.push(e);
    }
  }
  for (int i = 0; i < n - 1; ++i) {
    cout << ans[i] << endl;
  }
}
