import sys
from sys import stdin, stdout
n = int(input())
edges = []
g = [[] for i in range(n)]
x = -1
for i in range(n - 1):
    u, v = map(int, sys.stdin.readline().split(' '))
    u -= 1
    v -= 1
    if (u > v):
        u, v = v, u
    g[u].append(v)
    g[v].append(u)
    if (len(g[u]) > 2):
        x = u
    if (len(g[v]) > 2):
        x = v
    edges.append((u, v))

ans = { }
if (x == -1):
    for i in range(n - 1):
        print(i)
else:
    i = 0
    for v in g[x]:
        if (v > x):
            ans[x, v] = i
        else:
            ans[v, x] = i
        i += 1
    for e in edges:
        if e in ans:
            print(ans[e])
        else:
            print(i)
            i += 1