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]))

n = int(eval(input()))

G = [[] for _ in range(n)]

edge  = []

for _ in range(n-1):

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

    a -= 1

    b -= 1

    G[a].append(b)

    edge.append(b)



from collections import deque



q = deque()

color = [0]*n

q.append(0)

while q:

    cur = q.popleft()

    c = 1

    for nx in G[cur]:

        if color[cur] == c:

            c += 1

        color[nx] = c

        c += 1

        q.append(nx)



print((max(color)))

for e in edge:

    print((color[e]))
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]))

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

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

-G = [[] for i in range(n + 1)] -G_order = [] -for i in range(n - 1): +G = [[] for _ in range(n)] +edge = [] +for _ in range(n - 1): +    a -= 1 +    b -= 1 -    G_order.append(b) +    edge.append(b) -q = deque([1]) -color = [0] * (n + 1) +q = deque() +color = [0] * n +q.append(0) -        if c == color[cur]: +        if color[cur] == c: -for i in G_order: -    print((color[i])) +for e in edge: +    print((color[e]))