N = int(input())
g = {i : [] for i in range(N+1)}
dist = [2**20 for _ in range(N+1)]
visited = [0] * (N+1)
s = [1]
E = []
for num in range(N-1):
    u, v = list(map(int, input().split()))
    # u, v = num+1, num+2
    g[u].append(v)
    g[v].append(u)
    E.append( (u, v, num) )

for i in range(1, N+1):
    if len(g[i]) == 1:
        s.append(i)
        visited[i] = 1
        dist[i] = 0
pos = 0
while pos < N:
    u = s[pos]
    pos += 1
    for v in g[u]:
        if not visited[v]:
            visited[v] = 1
            s.append(v)
            dist[v] = dist[u] + 1
 
keys = [dist[u]+dist[v] for u, v, _ in E]
X = [(e, n) for n, e in enumerate(sorted(range(N-1), key=lambda x: keys[x]))]
 
# print(time.time() - start)
 
print('\n'.join([str(i) for _, i in sorted(X)]))
print()