import copy



n=int(eval(input()))

org_set=set([i for i in range(1,10**5)])

edges=[]

relations={}

nodes=[]

for i in range(n-1):

    a,b=list(map(int,input().split(" ")))

    edges.append([a,b])

    relations.setdefault(a,[]).append(b)

    nodes.append([])

nodes.append([])

nodes.append([])



max_color=0

for start in range(1,n+1):

    targets=relations.get(start,[])

    color=1

    for target in targets:

        if color in nodes[start]:

            color+=1

        else:

            pass

        nodes[target].append(color)

        if color>=max_color:

            max_color=color

        color+=1



print(max_color)

for edge in edges:

    print((nodes[edge[1]][0]))
n=int(eval(input()))

edges=[]

relations={}

nodes=[0,0]

for i in range(n-1):

    a,b=list(map(int,input().split(" ")))

    edges.append([a,b])

    relations.setdefault(a,[]).append(b)

    nodes.append(0)



max_color=0

for start in range(1,n+1):

    targets=relations.get(start,[])

    color=1

    for target in targets:

        if color == nodes[start]:

            color+=1

        else:

            pass

        nodes[target]=color

        if color>=max_color:

            max_color=color

        color+=1



print(max_color)

for edge in edges:

    print((nodes[edge[1]]))
import copy

n = int(eval(input()))
org_set = set([i for i in range(1, 10**5)])
edges = []
relations = {}
nodes = []
for i in range(n - 1):
    a, b = list(map(int, input().split(" ")))
    edges.append([a, b])
    relations.setdefault(a, []).append(b)
    nodes.append([])
nodes.append([])
nodes.append([])
max_color = 0
for start in range(1, n + 1):
    targets = relations.get(start, [])
    color = 1
    for target in targets:
        if color in nodes[start]:
            color += 1
        else:
            pass
        nodes[target].append(color)
        if color >= max_color:
            max_color = color
        color += 1
print(max_color)
for edge in edges:
    print((nodes[edge[1]][0]))

n = int(eval(input()))
edges = []
relations = {}
nodes = [0, 0]
for i in range(n - 1):
    a, b = list(map(int, input().split(" ")))
    edges.append([a, b])
    relations.setdefault(a, []).append(b)
    nodes.append(0)
max_color = 0
for start in range(1, n + 1):
    targets = relations.get(start, [])
    color = 1
    for target in targets:
        if color == nodes[start]:
            color += 1
        else:
            pass
        nodes[target] = color
        if color >= max_color:
            max_color = color
        color += 1
print(max_color)
for edge in edges:
    print((nodes[edge[1]]))

-import copy - -org_set = set([i for i in range(1, 10**5)]) -nodes = [] +nodes = [0, 0] -    nodes.append([]) -nodes.append([]) -nodes.append([]) +    nodes.append(0) -        if color in nodes[start]: +        if color == nodes[start]: -        nodes[target].append(color) +        nodes[target] = color -    print((nodes[edge[1]][0])) +    print((nodes[edge[1]]))