

"""
NTC here
"""
import sys
inp = sys.stdin.readline
def input(): return inp().strip()
# flush= sys.stdout.flush
# import threading
# sys.setrecursionlimit(10**6)
# threading.stack_size(2**26)

def iin(): return int(input())


def lin(): return list(map(int, input().split()))


# range = xrange
# input = raw_input

def BFS(s, adj):
    level = []
    parent = {s: None}
    lv = 1
    u = [s]
    while u:  # runs till u is []
        nextu = []
        nx = []
        for i in u:
            for v in adj[i]:
                if v not in parent:
                    parent[v] = i
                    nx.append((i, v))
                    nextu.append(v)
        level.append(nx)
        u = nextu.copy()
    level = level[::-1]
    ans = {}
    ch = 0
    for l in level:
        for p in l:
            ans[p]=ch
            ch+=1
    return ans


def main():
    from collections import defaultdict
    T = 1
    while T:
        T-=1
        n = iin()
        e = [ lin() for i in range(n-1)]
        adj = [set() for i in range(n+1)]
        for i, j in e:
            adj[i].add(j)
            adj[j].add(i)
        # s = 1
        # for i in range(1, n+1):
        #     if len(adj[i])>len(adj[s]):
        #         s = i
        # ans = BFS(s, adj)
        # print(ans)
        # for i, j in e:
        #     print(ans[(i, j)] if (i, j) in ans else ans[(j, i)])
        ch = 0
        ans = {}
        ln = defaultdict(set)
        for i in range(1, n+1):
            l = len(adj[i])
            ln[l].add(i)
        # print(ln)
        while ln[1]:
            a = ln[1]
            ln[1]=set()
            for i in a:
                if not adj[i]:continue
                x, y = i, list(adj[i])[0]
                ans[(x, y)]=ch
                ch+=1
                l = len(adj[y])
                adj[y].remove(x)
                adj[x]=set()
                if l>1:ln[l].remove(y)
                l = len(adj[y])
                if l>0:
                    ln[l].add(y)
            # print(ln, ans)
            # print(adj)
        for i, j in e:
            print(ans[(i, j)] if (i, j) in ans else ans[(j, i)])

main()

# threading.Thread(target=main).start()


"""
1
5
1 3
1 4
1 6
2 6
0 5
"""