from collections import deque
Q=deque()
n=int(input())
graph={}
d=[0 for i in range(n+1)]

for i in range(n):
    tmp=list(map(int,input().split()))
    graph[tmp[0]]=[0 for j in range(n+1)]
    for j in range(tmp[1]):
        graph[tmp[0]][tmp[2+j]]=1

Q.append(1)
while len(Q) is not 0:
    number=Q[0]
    if 1 in graph[number]:
        for i in range(graph[number].count(1)):
            Q.append(graph[number].index(1))
            if d[graph[number].index(1)] is 0:
                d[graph[number].index(1)]=d[number]+1
            graph[number][graph[number].index(1)]=0
        
    Q.popleft()

for i in range(n):
    if i==0:
        print(i+1,0)
    else:
        if d[i+1]==0:
            print(i+1,-1)
        else:
            print(i+1,d[i+1]) from collections import deque Q=deque() Q deque() deque n=int(input()) n int(input()) int input() input graph={} graph {} 0 for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) 0 d=[0 for i in range(n+1)] d [0 for i in range(n+1)] for i in range(n):
    tmp=list(map(int,input().split()))
    graph[tmp[0]]=[0 for j in range(n+1)]
    for j in range(tmp[1]):
        graph[tmp[0]][tmp[2+j]]=1 i range(n) range n tmp=list(map(int,input().split())) tmp list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split 0 for j in range(n+1) for j in range(n+1) j range(n+1) range n+1 n 1 for j in range(n+1) 0 graph[tmp[0]]=[0 for j in range(n+1)] graph[tmp[0]] graph tmp[0] tmp 0 [0 for j in range(n+1)] for j in range(tmp[1]):
        graph[tmp[0]][tmp[2+j]]=1 j range(tmp[1]) range tmp[1] tmp 1 graph[tmp[0]][tmp[2+j]]=1 graph[tmp[0]][tmp[2+j]] [tmp[0]] graph tmp[0] tmp 0 tmp[2+j] tmp 2+j 2 j 1 Q.append(1) Q.append Q append 1 while len(Q) is not 0:
    number=Q[0]
    if 1 in graph[number]:
        for i in range(graph[number].count(1)):
            Q.append(graph[number].index(1))
            if d[graph[number].index(1)] is 0:
                d[graph[number].index(1)]=d[number]+1
            graph[number][graph[number].index(1)]=0
        
    Q.popleft() len(Q) is not 0 len(Q) len Q 0 number=Q[0] number Q[0] Q 0 if 1 in graph[number]:
        for i in range(graph[number].count(1)):
            Q.append(graph[number].index(1))
            if d[graph[number].index(1)] is 0:
                d[graph[number].index(1)]=d[number]+1
            graph[number][graph[number].index(1)]=0
        
     1 in graph[number] 1 graph[number] graph number for i in range(graph[number].count(1)):
            Q.append(graph[number].index(1))
            if d[graph[number].index(1)] is 0:
                d[graph[number].index(1)]=d[number]+1
            graph[number][graph[number].index(1)]=0
        
     i range(graph[number].count(1)) range graph[number].count(1) [number].count [number] graph number count 1 Q.append(graph[number].index(1)) Q.append Q append graph[number].index(1) [number].index [number] graph number index 1 if d[graph[number].index(1)] is 0:
                d[graph[number].index(1)]=d[number]+1
             d[graph[number].index(1)] is 0 d[graph[number].index(1)] d graph[number].index(1) [number].index [number] graph number index 1 0 d[graph[number].index(1)]=d[number]+1 d[graph[number].index(1)] d graph[number].index(1) [number].index [number] graph number index 1 d[number]+1 d[number] d number 1 graph[number][graph[number].index(1)]=0 graph[number][graph[number].index(1)] [number] graph number graph[number].index(1) [number].index [number] graph number index 1 0 Q.popleft() Q.popleft Q popleft for i in range(n):
    if i==0:
        print(i+1,0)
    else:
        if d[i+1]==0:
            print(i+1,-1)
        else:
            print(i+1,d[i+1]) i range(n) range n if i==0:
        print(i+1,0)
    else:
        if d[i+1]==0:
            print(i+1,-1)
        else:
            print(i+1,d[i+1]) i==0 i 0 print(i+1,0) print i+1 i 1 0 if d[i+1]==0:
            print(i+1,-1)
        else:
            print(i+1,d[i+1]) d[i+1]==0 d[i+1] d i+1 i 1 0 print(i+1,-1) print i+1 i 1 -1 print(i+1,d[i+1]) print i+1 i 1 d[i+1] d i+1 i 1 number=Q[0] Q[0] number Q=deque() deque() Q tmp=list(map(int,input().split())) list(map(int,input().split())) tmp n=int(input()) int(input()) n graph={} {} graph d=[0 for i in range(n+1)] [0 for i in range(n+1)] d
from collections import deque
Q=deque()
n=int(input())
graph={}
d=[0 for i in range(n+1)]

for i in range(n):
    tmp=list(map(int,input().split()))
    graph[tmp[0]]=[0 for j in range(n+1)]
    for j in range(tmp[1]):
        graph[tmp[0]][tmp[2+j]]=1

Q.append(1)
while len(Q) is not 0:
    number=Q[0]
    if 1 in graph[number]:
        for i in range(graph[number].count(1)):
            Q.append(graph[number].index(1))
            if d[graph[number].index(1)] is 0:
                d[graph[number].index(1)]=d[number]+1
            graph[number][graph[number].index(1)]=0
        
    Q.popleft()

for i in range(n):
    if i==0:
        print(i+1,0)
    else:
        if d[i+1]==0:
            print(i+1,-1)
        else:
            print(i+1,d[i+1])
