# ABC146 D - Coloring Edges on Tree

from collections import deque



n = int(eval(input()))

E = [[] for _ in range(n + 1)]

edge_order = []



for i in range(n-1):

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

    E[a].append(b)

    edge_order.append(b)



# 頂点1からBFS

q = deque([1])

color = [0] * (n+1) 

while q:

    V = q.popleft()

    c = 1

    for nv in E[V]:

        if c == color[V]:

            c += 1

        color[nv] = c

        c += 1

        q.append(nv)



print((max(color)))

for i in edge_order:

    print((color[i]))



n=int(eval(input()))

G=[[] for i in range(n+1)]

G_order=[]

for i in range(n-1):

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

  G[a].append(b)

  G_order.append(b)



from collections import deque

q=deque([1])

color=[0]*(n+1)

while q:

  cur=q.popleft()

  c=1

  for nx in G[cur]:

    if c==color[cur]:

      c+=1

    color[nx]=c

    c+=1

    q.append(nx)



print((max(color)))

for i in G_order:

  print((color[i]))

# ABC146 D - Coloring Edges on Tree
from collections import deque

n = int(eval(input()))
E = [[] for _ in range(n + 1)]
edge_order = []
for i in range(n - 1):
    a, b = list(map(int, input().split()))
    E[a].append(b)
    edge_order.append(b)
# 頂点1からBFS
q = deque([1])
color = [0] * (n + 1)
while q:
    V = q.popleft()
    c = 1
    for nv in E[V]:
        if c == color[V]:
            c += 1
        color[nv] = c
        c += 1
        q.append(nv)
print((max(color)))
for i in edge_order:
    print((color[i]))

n = int(eval(input()))
G = [[] for i in range(n + 1)]
G_order = []
for i in range(n - 1):
    a, b = list(map(int, input().split()))
    G[a].append(b)
    G_order.append(b)
from collections import deque

q = deque([1])
color = [0] * (n + 1)
while q:
    cur = q.popleft()
    c = 1
    for nx in G[cur]:
        if c == color[cur]:
            c += 1
        color[nx] = c
        c += 1
        q.append(nx)
print((max(color)))
for i in G_order:
    print((color[i]))

-# ABC146 D - Coloring Edges on Tree +n = int(eval(input())) +G = [[] for i in range(n + 1)] +G_order = [] +for i in range(n - 1): +    a, b = list(map(int, input().split())) +    G[a].append(b) +    G_order.append(b) -n = int(eval(input())) -E = [[] for _ in range(n + 1)] -edge_order = [] -for i in range(n - 1): -    a, b = list(map(int, input().split())) -    E[a].append(b) -    edge_order.append(b) -# 頂点1からBFS -    V = q.popleft() +    cur = q.popleft() -    for nv in E[V]: -        if c == color[V]: +    for nx in G[cur]: +        if c == color[cur]: -        color[nv] = c +        color[nx] = c -        q.append(nv) +        q.append(nx) -for i in edge_order: +for i in G_order: