from collections import Counter
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce

# sys.setrecursionlimit(10000000)


def input():
    return sys.stdin.readline().strip()


def iinput():
    return int(input())


def tinput():
    return input().split()


def rinput():
    return map(int, tinput())


def rlinput():
    return list(rinput())


mod = int(1e9)+7


def factors(n):
    return set(reduce(list.__add__,
                      ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))


# ----------------------------------------------------

def dfs(i):
    visited[i] = True
    for nd in g[i]:
        if not visited[nd]:
            got = labels.pop(0)
            g[i][nd] = got
            g[nd][i] = got
            dfs(nd)
    


if __name__ == "__main__":
    n = iinput()
    g = defaultdict(dict)
    edges = []
    for i in range(n-1):
        u, v = rinput()
        edges.append((u, v))
        g[u][v] = -1
        g[v][u] = -1
    mx=[]
    mxp=-1
    for i in g:
        if len(g[i])>len(mx):
            mxp=i
            mx=g[i]
            break
    curr=0
    # print(mx,mxp)
    for i in mx:
        g[mxp][i]=curr
        g[i][mxp]=curr
        curr+=1
    # print(g)
    for u,v in edges:
        if g[u][v]==-1:
            print(curr)
            curr+=1
        else:
            print(g[u][v])

    


