#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
int ans[maxn], n, d[maxn];
struct Edge {
  int from, to;
  Edge(int f, int t) : from(f), to(t) {}
};
vector<int> G[maxn];
vector<Edge> edge;
int vis[maxn];
void bfs(int s) {
  int cnt = n - 2;
  queue<int> Q;
  int i, j;
  Q.push(s);
  vis[s] = 1;
  while (!Q.empty()) {
    int v = Q.front();
    Q.pop();
    for (i = 0; i < G[v].size(); ++i) {
      int temp = G[v][i];
      Edge e = edge[temp];
      if (vis[e.to]) continue;
      ans[temp >> 1] = cnt;
      --cnt;
      Q.push(e.to);
      vis[e.to] = 1;
    }
  }
}
void solve() {
  int i, j, f, t;
  cin >> n;
  for (i = 0; i < n - 1; ++i) {
    cin >> f >> t;
    edge.push_back(Edge(f, t));
    edge.push_back(Edge(t, f));
    int m = edge.size();
    G[f].push_back(m - 2);
    G[t].push_back(m - 1);
    ++d[t];
    ++d[f];
  }
  for (i = 1; i <= n; ++i) {
    if (d[i] == 1) break;
  }
  bfs(i);
  for (i = 0; i < n - 1; ++i) cout << ans[i] << '\n';
}
int main() {
  int t, i, j;
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
