import sys;readline = sys.stdin.readline
def i1(): return int(readline())
def nl(): return [int(s) for s in readline().split()]
def nn(n): return [int(readline()) for i in range(n)]
def nnp(n,x): return [int(readline())+x for i in range(n)]
def nmp(n,x): return (int(readline())+x for i in range(n))
def nlp(x): return [int(s)+x for s in readline().split()]
def nll(n): return [[int(s) for s in readline().split()] for i in range(n)]
def mll(n): return ([int(s) for s in readline().split()] for i in range(n))
def s1(): return readline().rstrip()
def sl(): return [s for s in readline().split()]
def sn(n): return [readline().rstrip() for i in range(n)]
def sm(n): return (readline().rstrip() for i in range(n))
def redir(s): global readline;import os;fn=sys.argv[0] + f'/../in-{s}.txt';readline = open(fn).readline if os.path.exists(fn) else readline
import os;
if 'DEPTH' in os.environ:
    def printd(*a,**aa):
        print(*a,**aa)
else:
    def printd(*a,**aa):
        pass

redir('c')
n = i1()
nodes = [[] for i in range(n)]
for i in range(n-1):
    u, v = nlp(-1)
    nodes[u].append((v,i))
    nodes[v].append((u,i))
printd(nodes)
printd([len(i) for i in nodes])
# leafs = [i for i in range(n) if len(nodes[i]) == 1]
# printd(leafs)
h3 = set()
for i in (nodes[i][0] for i in range(n) if len(nodes[i]) == 1):
    h3.add(i[1])
    if len(h3) == 3:
        break
# printd(leafs)
labels = [-1]*(n-1)
# h3 = sorted(set([i[1] for i in leafs[:3]]))  # set for test #19 one edge
printd("h3", h3)
printd("labels", labels)
for i,h in enumerate(h3):
    labels[h] = i
printd("labels", labels)
j = len(h3)
for i in range(n-1):
    if labels[i] < 0:
        labels[i] = j
        j += 1
# h3 = [0,1,3]
printd(h3)
printd(labels)
print('\n'.join(str(i) for i in labels))

