#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long power(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) ans *= a;
    a = a * a;
    b >>= 1;
  }
  return ans;
}
long long powm(long long a, long long b) {
  a %= MOD;
  long long ans = 1;
  while (b > 0) {
    if (b & 1) ans = (ans * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return ans;
}
void IO() {}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  IO();
  ;
  int n;
  cin >> n;
  vector<int> graph[n + 1], degree(n + 1), ans(n + 1, -1);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
    degree[u]++;
    degree[v]++;
  }
  int res = 0;
  for (int u = 1; u <= n; u++) {
    if (degree[u] == 1)
      for (int v : graph[u])
        if (ans[v] == -1) ans[v] = res++;
  }
  for (int u = 1; u <= n; u++)
    for (int v : graph[u])
      if (ans[v] == -1) ans[v] = res++;
  for (int i = 1; i <= n - 1; i++) cout << ans[i] << "\n";
  return 0;
}
