import math,sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
li = lambda:list(map(int,input().split()))



def dfs(s,n,d,c):
    visited=[False]*(n+1)
    queue=[]
    queue.append(s)
    visited[s]=True
    f=1
    x=0
    y=n-2
    while queue:
        s=queue.pop(0)
        #print(s)
        for i in d[s]:
            if(visited[i]==False):
                if(f):
                    c[(s,i)]=x
                    x+=1
                    f=0
                else:
                    c[(s,i)]=y
                    y-=1
                    f=1
                queue.append(i)
                visited[i]=True
    

def case():
    n=int(input())
    c=defaultdict(int)
    d=defaultdict(list)
    visited=[0]*(n+1)
    a=[]
    for i in range(n-1):
        p,q=li()
        a.append((p,q))
        d[p].append(q)
        d[q].append(p)
    x=0
    y=n-2
    #print(d)
    dfs(1,n,d,c)
    for i in a:
        print(i,c[i])
    
    
f=1
for _ in range(1):
    case()