#include <bits/stdc++.h>
using namespace std;
const long long md = 1e9 + 7;
const int xn = -1 + 10;
const int xm = 5e5;
const int SQ = 320;
const int sq = 1e3 + 10;
const long long inf = 1e18 + 10;
long long power(long long a, long long b) {
  return (!b ? 1
             : (b & 1 ? a * power(a * a % md, b / 2) % md
                      : power(a * a % md, b / 2) % md));
}
int n, h[xn], ind[xn], ans[xn], start[xn], second;
pair<long long, int> E[xn];
long long sz[xn];
vector<pair<long long, int> > adj[xn], Flor[xn];
vector<int> barg;
map<pair<long long, int>, int> mp;
bool mark[xn], vis[xn];
void DFS(int v) {
  mark[v] = true;
  int t = 0;
  sz[v] = 1;
  start[v] = second++;
  for (int i = 0; i < adj[v].size(); i++) {
    int u = adj[v][i].first, id = adj[v][i].second;
    if (mark[u]) continue;
    h[u] = h[v]++;
    ind[u] = id;
    DFS(u);
    sz[v] += sz[u];
  }
  if (t == 0) barg.push_back(v), vis[v] = true;
}
long long f(int v, int u) {
  if (h[u] < h[v]) swap(v, u);
  return h[u];
}
bool cmp(pair<long long, int> i, pair<long long, int> j) {
  return f(i.first, i.second) < f(j.first, j.second);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int v, u;
    cin >> v >> u;
    adj[v].push_back({u, i});
    adj[u].push_back({v, i});
    E[i] = {v, u};
    mp[{v, u}] = i;
  }
  DFS(1);
  sort(E, E + n - 1, cmp);
  int res = 0;
  for (int i = 0; i < n - 1; i++) ans[mp[{E[i].first, E[i].second}]] = res++;
  for (int i = 0; i < n - 1; i++) cout << ans[i] << '\n';
  return 0;
}
