#include <bits/stdc++.h>
using namespace std;
queue<int> que;
bool vst[100020];
vector<int> adj[100020];
int nn = 0;
map<pair<int, int>, int> mp;
void bfs() {
  while (!que.empty()) {
    int u = que.front();
    vst[u] = 1;
    que.pop();
    for (int i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i];
      if (vst[v]) continue;
      mp[pair<int, int>(u, v)] = mp[pair<int, int>(v, u)] = nn++;
      que.push(v);
    }
  }
}
int uu[100020], vv[100020];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n - 1; i++) {
    scanf("%d%d", &uu[i], &vv[i]);
    adj[uu[i]].push_back(vv[i]);
    adj[vv[i]].push_back(uu[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (adj[i].size() == 1) {
      que.push(i);
      vst[i] = 1;
    }
  }
  bfs();
  for (int i = 1; i <= n - 1; i++) {
    printf("%d\n", max(mp[pair<int, int>(uu[i], vv[i])],
                       mp[pair<int, int>(vv[i], uu[i])]));
  }
  return 0;
}
