#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 100000;
struct Edge {
  long long u, i;
};
vector<Edge> graph[MAXN];
long long colors[MAXN];
long long dist[MAXN];
long long indx[MAXN];
void calcd(long long v, long long p, long long d) {
  dist[v] = d;
  for (auto u : graph[v]) {
    if (u.u == p) continue;
    indx[u.u] = u.i;
    calcd(u.u, v, d + 1);
  }
}
bool cmp(const long long a, const long long b) { return dist[a] > dist[b]; }
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  fill(colors, colors + n - 1, -1);
  for (long long i = 0; i < n - 1; ++i) {
    long long a, b;
    cin >> a >> b;
    a--, b--;
    graph[a].push_back({b, i});
    graph[b].push_back({a, i});
  }
  calcd(0, -1, 0);
  vector<long long> vert(n);
  iota(vert.begin(), vert.end(), 0);
  sort(vert.begin(), vert.end(), cmp);
  for (long long i = 0; i < n - 1; ++i) colors[indx[vert[i]]] = i;
  for (long long i = 0; i < n - 1; ++i) cout << colors[i] << '\n';
  return 0;
}
