#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
const int SQRTN = 320;
const int LOGN = 20;
const double PI = acos(-1);
const double TAU = 2 * PI;
int n;
vector<vector<int> > g;
vector<pair<int, int> > e, logest_path_edges;
int cur, mxd;
void dfs(int node, int prt, int dist) {
  if (dist > mxd) {
    mxd = dist;
    cur = node;
  }
  for (int i = 0; i < g[node].size(); i++) {
    if (g[node][i] == prt) continue;
    dfs(g[node][i], node, dist + 1);
  }
}
void dfs2(int node, int prt, int dist) {
  if (dist > mxd) {
    mxd = dist;
    cur = node;
  }
  for (int i = 0; i < g[node].size(); i++) {
    if (g[node][i] == prt) continue;
    dfs2(g[node][i], node, dist + 1);
  }
}
int destenation;
bool dfs3(int node, int prt) {
  if (node == destenation) return true;
  for (int i = 0; i < g[node].size(); i++) {
    if (g[node][i] == prt) continue;
    if (dfs3(g[node][i], node)) {
      logest_path_edges.push_back(make_pair(node, g[node][i]));
      return true;
    }
  }
}
map<pair<int, int>, int> idx;
int ans[N];
int LF = 0, Right;
inline void solve() {
  cin >> n;
  g.resize(n + 1);
  memset(ans, -1, sizeof ans);
  Right = n - 1;
  for (int i = 1, a, b; i < n; i++) {
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
    idx[make_pair(min(a, b), max(a, b))] = i;
  }
  dfs(1, 0, 0);
  int x = cur;
  mxd = 0;
  dfs2(cur, 0, 0);
  destenation = x;
  dfs3(cur, -1);
  for (int i = 0; i < logest_path_edges.size(); i++) {
    pair<int, int> tmp = logest_path_edges[i];
    if (tmp.first > tmp.second) swap(tmp.first, tmp.second);
    if (i & 1) {
      ans[idx[tmp]] = LF++;
    } else {
      ans[idx[tmp]] = Right--;
    }
  }
  for (int i = 1; i < n; i++) {
    if (ans[i] == -1)
      printf("%d\n", LF++);
    else
      printf("%d\n", ans[i]);
  }
}
signed main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
