def bfs():
    while q!=[]:
        color[q[0]-1]="grey"
        for i in m[q[0]-1]:
            if i==0:continue
            if color[i-1]=="white":
                color[i-1]="grey"
                q.append(i)
                d[i-1]=d[q[0]-1]+1
        del q[0]

n=input()
d=[0]*n
m=[[0]*n for _ in xrange(n)]
info=[0]*n
color=["white"]*n
for i in xrange(n):
    info[i]=map(int,raw_input().split())
    if info[i][1]==0:
        pass
    else:
       for j in info[i][2:]:
           m[info[i][0]-1][j-1]=j
q=[1]
bfs()
for i in xrange(n):
    if i!=0 and d[i]==0:
        print i+1,-1
    else:
        print i+1,d[i] def bfs():
    while q!=[]:
        color[q[0]-1]="grey"
        for i in m[q[0]-1]:
            if i==0:continue
            if color[i-1]=="white":
                color[i-1]="grey"
                q.append(i)
                d[i-1]=d[q[0]-1]+1
        del q[0] bfs while q!=[]:
        color[q[0]-1]="grey"
        for i in m[q[0]-1]:
            if i==0:continue
            if color[i-1]=="white":
                color[i-1]="grey"
                q.append(i)
                d[i-1]=d[q[0]-1]+1
        del q[0] q!=[] q [] color[q[0]-1]="grey" color[q[0]-1] color q[0]-1 q[0] q 0 1 "grey" for i in m[q[0]-1]:
            if i==0:continue
            if color[i-1]=="white":
                color[i-1]="grey"
                q.append(i)
                d[i-1]=d[q[0]-1]+1
         i m[q[0]-1] m q[0]-1 q[0] q 0 1 if i==0:continue
             i==0 i 0 if color[i-1]=="white":
                color[i-1]="grey"
                q.append(i)
                d[i-1]=d[q[0]-1]+1
         color[i-1]=="white" color[i-1] color i-1 i 1 "white" color[i-1]="grey" color[i-1] color i-1 i 1 "grey" q.append(i) q.append q append i d[i-1]=d[q[0]-1]+1 d[i-1] d i-1 i 1 d[q[0]-1]+1 d[q[0]-1] d q[0]-1 q[0] q 0 1 1 del q[0] q[0] q 0 n=input() n input() input d=[0]*n d [0]*n [0] 0 n [0]*n for _ in xrange(n) for _ in xrange(n) _ xrange(n) xrange n for _ in xrange(n) [0]*n [0] 0 n m=[[0]*n for _ in xrange(n)] m [[0]*n for _ in xrange(n)] info=[0]*n info [0]*n [0] 0 n color=["white"]*n color ["white"]*n ["white"] "white" n for i in xrange(n):
    info[i]=map(int,raw_input().split())
    if info[i][1]==0:
        pass
    else:
       for j in info[i][2:]:
           m[info[i][0]-1][j-1]=j i xrange(n) xrange n info[i]=map(int,raw_input().split()) info[i] info i map(int,raw_input().split()) map int raw_input().split() ().split () raw_input split if info[i][1]==0:
        pass
    else:
       for j in info[i][2:]:
           m[info[i][0]-1][j-1]=j info[i][1]==0 info[i][1] [i] info i 1 0 for j in info[i][2:]:
           m[info[i][0]-1][j-1]=j j info[i][2:] [i] info i 2: 2 m[info[i][0]-1][j-1]=j m[info[i][0]-1][j-1] [info[i][0]-1] m info[i][0]-1 info[i][0] [i] info i 0 1 j-1 j 1 j q=[1] q [1] 1 bfs() bfs for i in xrange(n):
    if i!=0 and d[i]==0:
        print i+1,-1
    else:
        print i+1,d[i] i xrange(n) xrange n if i!=0 and d[i]==0:
        print i+1,-1
    else:
        print i+1,d[i] i!=0 and d[i]==0 i!=0 i 0 d[i]==0 d[i] d i 0 print i+1 i 1 -1 print i+1 i 1 d[i] d i d=[0]*n [0]*n d q=[1] [1] q color=["white"]*n ["white"]*n color m=[[0]*n for _ in xrange(n)] [[0]*n for _ in xrange(n)] m def bfs():
    while q!=[]:
        color[q[0]-1]="grey"
        for i in m[q[0]-1]:
            if i==0:continue
            if color[i-1]=="white":
                color[i-1]="grey"
                q.append(i)
                d[i-1]=d[q[0]-1]+1
        del q[0] def bfs():
    while q!=[]:
        color[q[0]-1]="grey"
        for i in m[q[0]-1]:
            if i==0:continue
            if color[i-1]=="white":
                color[i-1]="grey"
                q.append(i)
                d[i-1]=d[q[0]-1]+1
        del q[0] bfs n=input() input() n info=[0]*n [0]*n info
def bfs():
    while q!=[]:
        color[q[0]-1]="grey"
        for i in m[q[0]-1]:
            if i==0:continue
            if color[i-1]=="white":
                color[i-1]="grey"
                q.append(i)
                d[i-1]=d[q[0]-1]+1
        del q[0]

n=input()
d=[0]*n
m=[[0]*n for _ in xrange(n)]
info=[0]*n
color=["white"]*n
for i in xrange(n):
    info[i]=map(int,raw_input().split())
    if info[i][1]==0:
        pass
    else:
       for j in info[i][2:]:
           m[info[i][0]-1][j-1]=j
q=[1]
bfs()
for i in xrange(n):
    if i!=0 and d[i]==0:
        print i+1,-1
    else:
        print i+1,d[i]