N= int(input())
E = [input().split()[2:] for _ in [0]*N]
Q = [0]
L = [0] + [-1]*N

    


while Q:
    top = Q.pop(0)
    for i in E[top]:
        i = int(i) - 1
        if L[i] < 0 :L[i] = L[top] +1 ; Q+= [i]

for i in range(N):print(i + 1 ,int(L[i]))
 N= int(input()) N int(input()) int input() input input().split()[2:] for _ in [0]*N for _ in [0]*N _ [0]*N [0] 0 N for _ in [0]*N input().split()[2:] ().split() ().split () input split 2: 2 E = [input().split()[2:] for _ in [0]*N] E [input().split()[2:] for _ in [0]*N] Q = [0] Q [0] 0 L = [0] + [-1]*N L [0] + [-1]*N [0] 0 [-1]*N [-1] -1 N while Q:
    top = Q.pop(0)
    for i in E[top]:
        i = int(i) - 1
        if L[i] < 0 :L[i] = L[top] +1 ; Q+= [i] Q top = Q.pop(0) top Q.pop(0) Q.pop Q pop 0 for i in E[top]:
        i = int(i) - 1
        if L[i] < 0 :L[i] = L[top] +1 ; Q+= [i] i E[top] E top i = int(i) - 1 i int(i) - 1 int(i) int i 1 if L[i] < 0 :L[i] = L[top] +1 ; L[i] < 0 L[i] L i 0 for i in range(N):print(i + 1 ,int(L[i])) i range(N) range N L = [0] + [-1]*N [0] + [-1]*N L top = Q.pop(0) Q.pop(0) top i = int(i) - 1 int(i) - 1 i N= int(input()) int(input()) N Q = [0] [0] Q E = [input().split()[2:] for _ in [0]*N] [input().split()[2:] for _ in [0]*N] E
N= int(input())
E = [input().split()[2:] for _ in [0]*N]
Q = [0]
L = [0] + [-1]*N

    


while Q:
    top = Q.pop(0)
    for i in E[top]:
        i = int(i) - 1
        if L[i] < 0 :L[i] = L[top] +1 ; Q+= [i]

for i in range(N):print(i + 1 ,int(L[i]))

