from operator import itemgetter, attrgetter, methodcaller

n = int(input())
d = dict()
a = list()
for i in range(n - 1):
    u, v = map(int, input().split())
    a.append([u, v, i])
    if u in d.keys():
        d[u] += 1
    else:
        d[u] = 1

    if v in d.keys():
        d[v] += 1
    else:
        d[v] = 1

b = list()
for i in range(n - 1):
    b.append(-1)
    a[i].append(min(d[a[i][0]], d[a[i][1]]))

a.sort(key=itemgetter(3))
c = 0

for i in range(n - 1):
    b[a[i][2]] = c
    c += 1

for i in range(n - 1):
    print(b[i])

