import atexit
import io
import sys

_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER


@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

import sys

def main():
    data = input().rstrip().split()
    n = int(data[0])
    
    edges = []
    
    g = list([] for _ in range(n))
    
    leafes = list(False for _ in range(n))
    counter = 0
    
    for _ in range(n-1):
        a, b = sorted(map(int, input().split()))
        a, b = a-1, b-1
        edges.append((a, b))
        g[a].append(b)
        g[b].append(a)
    
    for k, v in enumerate(g):
        if counter == 3:
            break
    
        if len(v) == 1:
            leafes[k] = True
            counter += 1
    
    l_counter = 0
    to_print = []
    
    for edge in edges:
        a, b = edge
    
        if leafes[a] or leafes[b]:
            to_print.append(l_counter)
            l_counter += 1
    
        else:
            to_print.append(counter)
            counter += 1
    
    for foo in to_print:
        print(foo)

main()