n=int(eval(input()))

node={i:[] for i in range(1,n+1)}

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

q=[]

for _ in range(n-1):

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

    node[a].append(b)

    node[b].append(a)

    q.append((a,b))



mother=q[0][0]

visited[mother]=True



d=[]

e=[]





paint={i:{} for i in range(1,n+1)}



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



#使う要素 node visited paint mother_paint の四つのリスト

c=1

for child in node[mother]:

    visited[child]=True

    paint[mother][child]=c

    paint[child][mother]=c

    mother_paint[child]=c

    c+=1

    d.append(child)

    

while d:

    for parent in d:

        p=1 

        for child in node[parent]:

            if visited[child]==False:

                visited[child]=True

                if p!=mother_paint[parent]:

                    paint[parent][child]=p

                    paint[child][parent]=p

                    mother_paint[child]=p

                    p+=1

                    e.append(child)

                else:

                    p+=1

                    paint[parent][child]=p

                    paint[child][parent]=p

                    mother_paint[child]=p

                    p+=1

                    e.append(child)

    if e:

        d=e

        e=[]

    else:

        d=[]

        e=[]

K=0

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

    K=max(K,len(node[i]))

print(K)

for i in range(n-1):

    s,t=q[i][0],q[i][1]

    print((paint[s][t]))
#problem1

from collections import deque

d=deque()

e=deque()



N=int(eval(input()))

graph=[[] for i in range(N+1)]

D=[]

for _ in range(N-1):

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

    graph[a].append(b)

    graph[b].append(a)

    D.append((a,b))

    

#頂点1からスタート

K=0

d.append(1)

visited=[False for i in range(N+1)]

color=[-1 for i in range(N+1)]

visited[1]=True

color[1]=-1

dic={}

while d:

    while d:

        x=d.popleft()

        par_color=color[x]

        c=1

        for node in graph[x]:

            if visited[node]==False:

                visited[node]=True

                e.append(node)                

                if c!=par_color:

                    color[node]=c

                    dic[(x,node)]=c

                elif c==par_color:

                    c+=1

                    color[node]=c

                    dic[(x,node)]=c

                c+=1

    if e:

        d=e

        e=deque()



A=max(color)

print(A)

for que in D:

    a,b=que

    if (a,b) in list(dic.keys()):

        print((dic[que]))

    else:

        print((dic[(b,a)]))

    
n = int(eval(input()))
node = {i: [] for i in range(1, n + 1)}
visited = [False for i in range(n + 1)]
q = []
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    node[a].append(b)
    node[b].append(a)
    q.append((a, b))
mother = q[0][0]
visited[mother] = True
d = []
e = []
paint = {i: {} for i in range(1, n + 1)}
mother_paint = [0 for i in range(n + 1)]
# 使う要素 node visited paint mother_paint の四つのリスト
c = 1
for child in node[mother]:
    visited[child] = True
    paint[mother][child] = c
    paint[child][mother] = c
    mother_paint[child] = c
    c += 1
    d.append(child)
while d:
    for parent in d:
        p = 1
        for child in node[parent]:
            if visited[child] == False:
                visited[child] = True
                if p != mother_paint[parent]:
                    paint[parent][child] = p
                    paint[child][parent] = p
                    mother_paint[child] = p
                    p += 1
                    e.append(child)
                else:
                    p += 1
                    paint[parent][child] = p
                    paint[child][parent] = p
                    mother_paint[child] = p
                    p += 1
                    e.append(child)
    if e:
        d = e
        e = []
    else:
        d = []
        e = []
K = 0
for i in range(1, n + 1):
    K = max(K, len(node[i]))
print(K)
for i in range(n - 1):
    s, t = q[i][0], q[i][1]
    print((paint[s][t]))

# problem1
from collections import deque

d = deque()
e = deque()
N = int(eval(input()))
graph = [[] for i in range(N + 1)]
D = []
for _ in range(N - 1):
    a, b = list(map(int, input().split()))
    graph[a].append(b)
    graph[b].append(a)
    D.append((a, b))
# 頂点1からスタート
K = 0
d.append(1)
visited = [False for i in range(N + 1)]
color = [-1 for i in range(N + 1)]
visited[1] = True
color[1] = -1
dic = {}
while d:
    while d:
        x = d.popleft()
        par_color = color[x]
        c = 1
        for node in graph[x]:
            if visited[node] == False:
                visited[node] = True
                e.append(node)
                if c != par_color:
                    color[node] = c
                    dic[(x, node)] = c
                elif c == par_color:
                    c += 1
                    color[node] = c
                    dic[(x, node)] = c
                c += 1
    if e:
        d = e
        e = deque()
A = max(color)
print(A)
for que in D:
    a, b = que
    if (a, b) in list(dic.keys()):
        print((dic[que]))
    else:
        print((dic[(b, a)]))

-n = int(eval(input())) -node = {i: [] for i in range(1, n + 1)} -visited = [False for i in range(n + 1)] -q = [] -for _ in range(n - 1): +# problem1 +from collections import deque + +d = deque() +e = deque() +N = int(eval(input())) +graph = [[] for i in range(N + 1)] +D = [] +for _ in range(N - 1): -    node[a].append(b) -    node[b].append(a) -    q.append((a, b)) -mother = q[0][0] -visited[mother] = True -d = [] -e = [] -paint = {i: {} for i in range(1, n + 1)} -mother_paint = [0 for i in range(n + 1)] -# 使う要素 node visited paint mother_paint の四つのリスト -c = 1 -for child in node[mother]: -    visited[child] = True -    paint[mother][child] = c -    paint[child][mother] = c -    mother_paint[child] = c -    c += 1 -    d.append(child) +    graph[a].append(b) +    graph[b].append(a) +    D.append((a, b)) +# 頂点1からスタート +K = 0 +d.append(1) +visited = [False for i in range(N + 1)] +color = [-1 for i in range(N + 1)] +visited[1] = True +color[1] = -1 +dic = {} -    for parent in d: -        p = 1 -        for child in node[parent]: -            if visited[child] == False: -                visited[child] = True -                if p != mother_paint[parent]: -                    paint[parent][child] = p -                    paint[child][parent] = p -                    mother_paint[child] = p -                    p += 1 -                    e.append(child) -                else: -                    p += 1 -                    paint[parent][child] = p -                    paint[child][parent] = p -                    mother_paint[child] = p -                    p += 1 -                    e.append(child) +    while d: +        x = d.popleft() +        par_color = color[x] +        c = 1 +        for node in graph[x]: +            if visited[node] == False: +                visited[node] = True +                e.append(node) +                if c != par_color: +                    color[node] = c +                    dic[(x, node)] = c +                elif c == par_color: +                    c += 1 +                    color[node] = c +                    dic[(x, node)] = c +                c += 1 -        e = [] +        e = deque() +A = max(color) +print(A) +for que in D: +    a, b = que +    if (a, b) in list(dic.keys()): +        print((dic[que])) -        d = [] -        e = [] -K = 0 -for i in range(1, n + 1): -    K = max(K, len(node[i])) -print(K) -for i in range(n - 1): -    s, t = q[i][0], q[i][1] -    print((paint[s][t])) +        print((dic[(b, a)]))