n=int(eval(input()))

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

d={}

f=[]

for i in range(n-1):

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

  d[min(a,b)*1000000+max(a,b)]=10**7

  s[a-1].append(b-1)

  s[b-1].append(a-1)

  f.append((a-1,b-1))

se={0}

mc=max(len(s[i])for i in range(n))

print(mc)

Q=[(0,i)for i in s[0]]

r=[-1]*n

r[0]=0

while Q:

  P=[]

  b=-1

  for i,j in Q:

    if j in se:continue

    if b!=i:x=1

    else:x+=1

    if r[i]==x:x+=1

    b=i

    se.add(j)

    for k in s[j]:

      P.append((j,k))

    d[min(i,j)*1000000+max(i,j)]=x

    r[j]=x

  Q=P

for i,j in f:print((d[min(i,j)*1000000+max(i,j)]))
n=int(eval(input()))

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

point=[0]*n

edges=[]

point_color=[-1]*n

edge_color={}

edge_to_int=lambda x,y:min(x,y)*100007+max(x,y)

for _ in range(n-1):

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

  a-=1

  b-=1

  edges.append((a,b))

  edge[a].append(b)

  edge[b].append(a)

  point[a]+=1

  point[b]+=1

ans=max(point)

ind=point.index(ans)

Q=[ind]

visited={ind}

while Q:

  P=[]

  for i in Q:

    color=0

    for j in edge[i]:

      if j in visited:continue

      visited.add(j)

      P.append(j)

      color+=1

      if point_color[i]==color:color+=1

      point_color[j]=color

      edge_color[edge_to_int(i,j)]=color

  Q=P

print(ans)

for a,b in edges:

  print((edge_color[edge_to_int(a,b)]))
n = int(eval(input()))
s = [[] for _ in range(n)]
d = {}
f = []
for i in range(n - 1):
    a, b = list(map(int, input().split()))
    d[min(a, b) * 1000000 + max(a, b)] = 10**7
    s[a - 1].append(b - 1)
    s[b - 1].append(a - 1)
    f.append((a - 1, b - 1))
se = {0}
mc = max(len(s[i]) for i in range(n))
print(mc)
Q = [(0, i) for i in s[0]]
r = [-1] * n
r[0] = 0
while Q:
    P = []
    b = -1
    for i, j in Q:
        if j in se:
            continue
        if b != i:
            x = 1
        else:
            x += 1
        if r[i] == x:
            x += 1
        b = i
        se.add(j)
        for k in s[j]:
            P.append((j, k))
        d[min(i, j) * 1000000 + max(i, j)] = x
        r[j] = x
    Q = P
for i, j in f:
    print((d[min(i, j) * 1000000 + max(i, j)]))

n = int(eval(input()))
edge = [[] for _ in range(n)]
point = [0] * n
edges = []
point_color = [-1] * n
edge_color = {}
edge_to_int = lambda x, y: min(x, y) * 100007 + max(x, y)
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    edges.append((a, b))
    edge[a].append(b)
    edge[b].append(a)
    point[a] += 1
    point[b] += 1
ans = max(point)
ind = point.index(ans)
Q = [ind]
visited = {ind}
while Q:
    P = []
    for i in Q:
        color = 0
        for j in edge[i]:
            if j in visited:
                continue
            visited.add(j)
            P.append(j)
            color += 1
            if point_color[i] == color:
                color += 1
            point_color[j] = color
            edge_color[edge_to_int(i, j)] = color
    Q = P
print(ans)
for a, b in edges:
    print((edge_color[edge_to_int(a, b)]))

-s = [[] for _ in range(n)] -d = {} -f = [] -for i in range(n - 1): +edge = [[] for _ in range(n)] +point = [0] * n +edges = [] +point_color = [-1] * n +edge_color = {} +edge_to_int = lambda x, y: min(x, y) * 100007 + max(x, y) +for _ in range(n - 1): -    d[min(a, b) * 1000000 + max(a, b)] = 10**7 -    s[a - 1].append(b - 1) -    s[b - 1].append(a - 1) -    f.append((a - 1, b - 1)) -se = {0} -mc = max(len(s[i]) for i in range(n)) -print(mc) -Q = [(0, i) for i in s[0]] -r = [-1] * n -r[0] = 0 +    a -= 1 +    b -= 1 +    edges.append((a, b)) +    edge[a].append(b) +    edge[b].append(a) +    point[a] += 1 +    point[b] += 1 +ans = max(point) +ind = point.index(ans) +Q = [ind] +visited = {ind} -    b = -1 -    for i, j in Q: -        if j in se: -            continue -        if b != i: -            x = 1 -        else: -            x += 1 -        if r[i] == x: -            x += 1 -        b = i -        se.add(j) -        for k in s[j]: -            P.append((j, k)) -        d[min(i, j) * 1000000 + max(i, j)] = x -        r[j] = x +    for i in Q: +        color = 0 +        for j in edge[i]: +            if j in visited: +                continue +            visited.add(j) +            P.append(j) +            color += 1 +            if point_color[i] == color: +                color += 1 +            point_color[j] = color +            edge_color[edge_to_int(i, j)] = color -for i, j in f: -    print((d[min(i, j) * 1000000 + max(i, j)])) +print(ans) +for a, b in edges: +    print((edge_color[edge_to_int(a, b)]))