import sys
input = sys.stdin.readline

n = int(input())

G = [[] for _ in range(n)]
edges = []

for edge in range(n-1):
    u,v = map(int, input().split())
    u-=1
    v-=1
    G[u].append((u,v))
    G[v].append((u,v))
    edges.append((u,v))

for node in range(n):
    if len(G[node]) >= 3:
        special = G[node][:3]
        out = []
        count = 3
        for edge in edges:
            if edge in special:
                out.append(str(special.index(edge)))
                continue
            out.append(str(count))
            count += 1
        print("\n".join(out))
        exit(0)

out = []
for i in range(n-1):
    out.append(str(i))
print("\n".join(out))
