#include <bits/stdc++.h>
using namespace std;
long long x, y;
vector<pair<long long, long long>> edge[200005];
vector<bool> visit(200005, false);
vector<long long> ans(200005, -1);
long long bin_pow(long long x, long long y, long long m) {
  long long ans;
  if (y == 0) return 1;
  ans = bin_pow(x, y / 2, m);
  if (y % 2 == 0) return ((ans * ans) % m);
  return (x * ((ans * ans) % m)) % m;
}
long long mult(long long a, long long b, long long m) {
  long long ans = ((a % m) * (b % m)) % m;
  return ans;
}
long long sum(long long a, long long b) {
  long long ans = (a % 1000000007 + b % 1000000007) % 1000000007;
  return ans;
}
long long diff(long long a, long long b) {
  long long ans =
      ((a % 1000000007) - (b % 1000000007) + 1000000007) % 1000000007;
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void dfs(long long n) {
  visit[n] = true;
  if (edge[n].size() == 1 && n != 1) {
    ans[edge[n][0].second] = y;
    y++;
    return;
  }
  for (long long i = 0; i < edge[n].size(); i++) {
    if (visit[edge[n][i].first] != true) {
      dfs(edge[n][i].first);
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) {
    long long n;
    cin >> n;
    y = 0;
    for (long long i = 0; i < n - 1; i++) {
      long long u, v;
      cin >> u >> v;
      edge[u].push_back(make_pair(v, i));
      edge[v].push_back(make_pair(u, i));
    }
    dfs(1);
    for (long long i = 0; i < n - 1; i++) {
      if (ans[i] == -1) {
        cout << y << endl;
        y++;
      } else
        cout << ans[i] << endl;
    }
  }
}
