#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[100005], visited(100005, 0);
long long par[100005], h[100005] = {0};
vector<pair<long long, long long> > ht;
map<pair<long long, long long>, long long> mp;
long long cnt = 0;
void dfs(long long v, long long parent) {
  visited[v] = 1;
  par[v] = parent;
  long long t = 0;
  for (auto x : adj[v]) {
    h[v] = max(h[v], h[x] + 1);
    if (x == parent) continue;
    dfs(x, v);
    t++;
  }
  if (t == 0) h[v] = 0;
}
int main() {
  long long n;
  cin >> n;
  vector<pair<long long, long long> > pr;
  long long m = n - 1;
  while (m--) {
    long long x, y;
    cin >> x >> y;
    pr.push_back({x, y});
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, -1);
  for (long long i = 1; i <= n; i++) {
    ht.push_back({h[i], i});
  }
  sort(ht.begin(), ht.end());
  for (auto x : ht) {
    long long v = x.second;
    long long p = par[v];
    if (p == -1) continue;
    mp[{p, v}] = cnt;
    mp[{v, p}] = cnt++;
  }
  for (auto x : pr) {
    cout << mp[x] << endl;
  }
}
