#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const int N = 100100;
int n, a[N], q;
int deg[N];
int vis[N];
map<pair<int, int>, int> mp;
pair<int, int> p[N];
vector<int> adj[N];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    if (u > v) swap(u, v);
    p[i] = {u, v};
    adj[u].push_back(v);
    adj[v].push_back(u);
    deg[u]++;
    deg[v]++;
  }
  int rt = 1, mx = deg[1];
  for (int i = 2; i <= n; i++) {
    if (deg[i] > mx) {
      mx = deg[i];
      rt = i;
    }
  }
  queue<int> q;
  vis[rt] = 1;
  q.push(rt);
  int c = 0;
  while (q.size()) {
    int u = q.front();
    q.pop();
    for (auto v : adj[u]) {
      if (!vis[v]) {
        vis[v] = 1;
        mp[{min(u, v), max(u, v)}] = c++;
        q.push(v);
      }
    }
  }
  for (int i = 0; i < n - 1; i++) printf("%d\n", mp[p[i]]);
  return 0;
}
