def answer(nodeCount, edges) :
  labels = [-1] * len(edges)
  threeAboveConnectedNodeNumber = 0
  labelNumbers = [i for i in range(3, len(edges))]
  mins = [0, 1, 2]
  tree = [[] for _ in range(nodeCount+1)]
  for i in range(len(edges)) :
    u, v, li = edges[i]
    tree[u].append(li)
    if len(tree[u]) == 3 :
      for j in range(0, 3) :
        labels[tree[u][j]] = mins.pop()
      break
    tree[v].append(li)
    if len(tree[v]) == 3 :
      for j in range(0, 3) :
        labels[tree[v][j]] = mins.pop()
      break
  if len(mins) == 3 :
    labels = labelNumbers + [e for e in range(len(edges))]
  else :
    for i in range(len(labels)) :
      if labels[i] == -1 :
        labels[i] = labelNumbers.pop()
  return "\n".join([str(i) for i in labels])

nodeCount = int(input())
edges = []
for i in range(nodeCount-1) :
  u, v = map(int, input().split())
  edges.append([u, v, i])
print(answer(nodeCount, edges))