#Breadth First Search
n=int(input())
V=[]
a=[1]
for i in range(n):
    V.append([int(i) for i in input().split()])
    a.append(0)
V=sorted(V,key=lambda x:x[0])
print('1 0')
d=1
c=0
w=[0]
p=[]
while c<n and w!=[]:
    i=0
    y=[]
 #   print(c)
    while c<n and i<len(w):
        j=2
        while j<2+V[w[i]][1] and c<n:
            if a[V[w[i]][j]-1]==0:
        #        print(a)
                a[V[w[i]][j]-1]=1
                p.append([V[w[i]][j],d])
                c+=1
                y.append(V[w[i]][j]-1)
            j+=1
        i+=1
    w=y
    d+=1
p=sorted(p, key=lambda x:x[0])
#print(p)
i=2
j=0
while i <=n and j<len(p):
    while p[j][0]>i:
        print(str(i) +" -1")
        i+=1
    print(str(p[j][0])+" "+str(p[j][1]))
    i+=1
    j+=1
while i<=n:
    print(str(i)+" -1")
    i+=1 n=int(input()) n int(input()) int input() input V=[] V [] a=[1] a [1] 1 for i in range(n):
    V.append([int(i) for i in input().split()])
    a.append(0) i range(n) range n int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i V.append([int(i) for i in input().split()]) V.append V append [int(i) for i in input().split()] a.append(0) a.append a append 0 V=sorted(V,key=lambda x:x[0]) V sorted(V,key=lambda x:x[0]) sorted V key=lambda x:x[0] key lambda x:x[0] x[0] x 0 x print('1 0') print '1 0' d=1 d 1 c=0 c 0 w=[0] w [0] 0 p=[] p [] while c<n and w!=[]:
    i=0
    y=[]
 #   print(c)
    while c<n and i<len(w):
        j=2
        while j<2+V[w[i]][1] and c<n:
            if a[V[w[i]][j]-1]==0:
        #        print(a)
                a[V[w[i]][j]-1]=1
                p.append([V[w[i]][j],d])
                c+=1
                y.append(V[w[i]][j]-1)
            j+=1
        i+=1
    w=y
    d+=1 c<n and w!=[] c<n c n w!=[] w [] i=0 i 0 y=[] y [] while c<n and i<len(w):
        j=2
        while j<2+V[w[i]][1] and c<n:
            if a[V[w[i]][j]-1]==0:
        #        print(a)
                a[V[w[i]][j]-1]=1
                p.append([V[w[i]][j],d])
                c+=1
                y.append(V[w[i]][j]-1)
            j+=1
        i+=1
     c<n and i<len(w) c<n c n i<len(w) i len(w) len w j=2 j 2 while j<2+V[w[i]][1] and c<n:
            if a[V[w[i]][j]-1]==0:
        #        print(a)
                a[V[w[i]][j]-1]=1
                p.append([V[w[i]][j],d])
                c+=1
                y.append(V[w[i]][j]-1)
            j+=1
         j<2+V[w[i]][1] and c<n j<2+V[w[i]][1] j 2+V[w[i]][1] 2 V[w[i]][1] [w[i]] V w[i] w i 1 c<n c n if a[V[w[i]][j]-1]==0:
        #        print(a)
                a[V[w[i]][j]-1]=1
                p.append([V[w[i]][j],d])
                c+=1
                y.append(V[w[i]][j]-1)
             a[V[w[i]][j]-1]==0 a[V[w[i]][j]-1] a V[w[i]][j]-1 V[w[i]][j] [w[i]] V w[i] w i j 1 0 a[V[w[i]][j]-1]=1 a[V[w[i]][j]-1] a V[w[i]][j]-1 V[w[i]][j] [w[i]] V w[i] w i j 1 1 p.append([V[w[i]][j],d]) p.append p append [V[w[i]][j],d] V[w[i]][j] [w[i]] V w[i] w i j d c+=1 c 1 y.append(V[w[i]][j]-1) y.append y append V[w[i]][j]-1 V[w[i]][j] [w[i]] V w[i] w i j 1 j+=1 j 1 i+=1 i 1 w=y w y d+=1 d 1 p=sorted(p, key=lambda x:x[0]) p sorted(p, key=lambda x:x[0]) sorted p key=lambda x:x[0] key lambda x:x[0] x[0] x 0 x i=2 i 2 j=0 j 0 while i <=n and j<len(p):
    while p[j][0]>i:
        print(str(i) +" -1")
        i+=1
    print(str(p[j][0])+" "+str(p[j][1]))
    i+=1
    j+=1 i <=n and j<len(p) i <=n i n j<len(p) j len(p) len p while p[j][0]>i:
        print(str(i) +" -1")
        i+=1
     p[j][0]>i p[j][0] [j] p j 0 i print(str(i) +" -1") print str(i) +" -1" str(i) str i " -1" i+=1 i 1 print(str(p[j][0])+" "+str(p[j][1])) print str(p[j][0])+" "+str(p[j][1]) str(p[j][0])+" " str(p[j][0]) str p[j][0] [j] p j 0 " " str(p[j][1]) str p[j][1] [j] p j 1 i+=1 i 1 j+=1 j 1 while i<=n:
    print(str(i)+" -1")
    i+=1 i<=n i n print(str(i)+" -1") print str(i)+" -1" str(i) str i " -1" i+=1 i 1 j+=1 1 j V=[] [] V c=0 0 c y=[] [] y w=[0] [0] w V=sorted(V,key=lambda x:x[0]) sorted(V,key=lambda x:x[0]) V c+=1 1 c w=y y w j=0 0 j i+=1 1 i j=2 2 j p=sorted(p, key=lambda x:x[0]) sorted(p, key=lambda x:x[0]) p i+=1 1 i a=[1] [1] a d=1 1 d i=0 0 i p=[] [] p n=int(input()) int(input()) n i+=1 1 i i+=1 1 i d+=1 1 d i=2 2 i j+=1 1 j
#Breadth First Search
n=int(input())
V=[]
a=[1]
for i in range(n):
    V.append([int(i) for i in input().split()])
    a.append(0)
V=sorted(V,key=lambda x:x[0])
print('1 0')
d=1
c=0
w=[0]
p=[]
while c<n and w!=[]:
    i=0
    y=[]
 #   print(c)
    while c<n and i<len(w):
        j=2
        while j<2+V[w[i]][1] and c<n:
            if a[V[w[i]][j]-1]==0:
        #        print(a)
                a[V[w[i]][j]-1]=1
                p.append([V[w[i]][j],d])
                c+=1
                y.append(V[w[i]][j]-1)
            j+=1
        i+=1
    w=y
    d+=1
p=sorted(p, key=lambda x:x[0])
#print(p)
i=2
j=0
while i <=n and j<len(p):
    while p[j][0]>i:
        print(str(i) +" -1")
        i+=1
    print(str(p[j][0])+" "+str(p[j][1]))
    i+=1
    j+=1
while i<=n:
    print(str(i)+" -1")
    i+=1