
# from collections import deque
import sys
from collections import defaultdict
sys.setrecursionlimit(10**6)


def main():
    E = []
    colors = []
    g = defaultdict(lambda: [])
    N = int(input())
    # N = 10**5
    dist = [2**20] * (N+1)
    fr = [0] * (N+1)
    visited = [0] * (N+1)
    for num in range(N-1):
        u, v = list(map(int, input().split()))
        # u, v = num+1, num+2
        g[u].append(v)
        g[v].append(u)
        E.append( (v, u, num) )
     
    def dst(u):
        visited[u] = 1
        if len(g[u]) == 1:
            dist[u] = 0
            dst(g[u][0])
            return 0
        else:
            for v in g[u]:
                if not visited[v]:
                    dst(v)
                    if dist[v] + 1 < dist[u]:
                        dist[u] = dist[v] + 1
                        fr[u] = v
            return dist[u]
    dst(1)
    X = [(e[2], n) for n, e in enumerate(sorted(E, key=lambda e: dist[e[0]] + dist[e[1]]))]
    for _, i in sorted(X):
        print(i)

        
import threading
threading.stack_size(10**8)
t = threading.Thread(target=main)
t.start()
t.join()