
def Solution():
    n = int(input())
    c = {}
    edges = []
    f, l = 0, n-2
    for i in range(n-1):
        u, v = map(int, input().split())
        edges.append((u,v))
        c.setdefault(u, 0)
        c.setdefault(v, 0)
        c[u] += 1
        c[v] += 1

    for i in edges:
        if(c[i[0]]==1 or c[i[1]]==1):
            print(f)
            f += 1
        else:
            print(l)
            l -= 1

if __name__ == "__main__":
    Solution()
