class Solution:
    def solve(self, n, queries):
        count = [0] * (n+1)
        node = 0
        for u, v in queries:
            count[u] += 1
            count[v] += 1
            if count[u] == 3:
                node = u
            if count[v] == 3:
                node = v
        ret = []
        i = 0
        j = 3 if node else 0
        for u, v in queries:
            if (u == node or v == node) and i < 3:
                ret.append(i)
                i += 1
            else:
                ret.append(j)
                j += 1
        return ret


def main():
    inp = lambda: [int(x) for x in input().split()]
    n = int(input())
    queries = [inp() for _ in range(n-1)]
    ans = Solution().solve(n, queries)
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()
