n = int(input())
degree = [0] * (10 ** 5 + 1)
edges = []
special_node = None

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

for u in range(n):
   if degree[u] >= 3:
      special_node = u
      break

start, end = 0, n - 2
for u, v in edges:
   if u == special_node or v == special_node:
      print(start)
      start += 1
   else:
      print(end)
      end -= 1

