#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> tree[N];
bool vis[N];
map<pair<int, int>, int> ans;
pair<int, int> in[N];
vector<int> ev, od;
int main() {
  int n;
  cin >> n;
  int u, v;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    tree[u].push_back(v);
    tree[v].push_back(u);
    in[i] = {u, v};
  }
  int st = 1, mx = 0;
  for (int i = 1; i <= n; i++)
    if (tree[i].size() > mx) {
      mx = tree[i].size();
      st = i;
    }
  int cnt = 0;
  queue<int> q;
  q.push(st);
  int cur;
  while (q.size()) {
    cur = q.front();
    q.pop();
    if (vis[cur]) continue;
    vis[cur] = 1;
    for (int i = 0; i < tree[cur].size(); i++) {
      if (vis[tree[cur][i]]) continue;
      ans[{cur, tree[cur][i]}] = cnt;
      ans[{tree[cur][i], cur}] = cnt++;
      q.push(tree[cur][i]);
    }
  }
  for (int i = 1; i < n; i++) cout << ans[in[i]] << endl;
  return 0;
}
