class Graph: #Directed
    def __init__(self, vertices):
        self.no_of_vertices = vertices
        self.graph = dict() #Adjacency
        for i in range(1, self.no_of_vertices+1):
            self.graph[i] = []
    
    def add_edge(self, u, v):
        self.graph[u].append(v)
        self.graph[v].append(u)
    
    

n = int(input())
g = Graph(n)

edges = []
for _ in range(n-1):
    [l, r] = [int(i) for i in input().split()]
    edges.append((l, r))

for (u,v) in edges:
    g.add_edge(u, v)

labels = [None]*(n-1)

for u in g.graph:
    if(len(g.graph[u])>2):
        break

l = 0
for i in range(n-1):
    if(u in edges[i]):
        labels[i] = l 
        l = l + 1

for i in range(n-1):
    if(labels[i]==None):
        labels[i] = l 
        l = l+1

for i in labels:
    print(i)