#include <bits/stdc++.h>
using namespace std;
long long powerFunction(long long x, long long y) {
  long long res = 1;
  long long p = 1000000007;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
bool prime[10000001];
long long P = 1000000007 - 2;
long long fact[10000001] = {0};
void sieveFunction(long long maxLimit) {
  memset(prime, true, sizeof(prime));
  prime[0] = prime[1] = false;
  for (long long i = 2; maxLimit >= i; i++) {
    if (prime[i]) {
      for (long long j = 2 * i; maxLimit >= j; j += i) prime[j] = false;
    }
  }
}
void factorialFunction(long long maxLimit) {
  fact[0] = 1;
  for (long long i = 1; i <= maxLimit; i++)
    fact[i] = (fact[i - 1] * i) % 1000000007;
  return;
}
long long nCr(long long n, long long r) {
  long long a = fact[n];
  long long b = powerFunction(fact[n - r], 1000000007 - 2);
  long long c = powerFunction(fact[r], 1000000007 - 2);
  return (a * (b % 1000000007 * c % 1000000007) % 1000000007) % 1000000007;
}
long long vis[3000005];
long long od[3000005];
signed main() {
  long long n;
  cin >> n;
  vector<pair<long long, long long>> adj[n + 1];
  long long ind;
  long long f;
  for (long long i = 0; i < n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    adj[u].push_back({i, v});
    adj[v].push_back({i, u});
  }
  long long p = 0;
  for (long long i = 1; i < n + 1; i++) {
    if ((long long)adj[i].size() < 3)
      continue;
    else {
      for (auto it : adj[i]) {
        if (vis[it.first] == 0) {
          vis[it.first] = p;
          p++;
        }
      }
    }
  }
  for (long long i = 0; i < n - 1; i++) {
    if (vis[i] == 0) {
      vis[i] = p;
      p++;
    }
    cout << vis[i] << "\n";
  }
}
