N= int(input())
E = [input().split()[2:] for _ in range(N)]
Q = [0]
L = [0] + [-1]*N
frag = [1] + [0]*N
def func(ide):
    global Q
    for i in E[ide]:
        i = int(i) - 1
        if frag[i] != 1:frag[i] = 1;L[i] = L[ide] +1 ;Q.append(i)
    

while Q:top = Q.pop(0);func(top)

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 range(N) for _ in range(N) _ range(N) range N for _ in range(N) input().split()[2:] ().split() ().split () input split 2: 2 E = [input().split()[2:] for _ in range(N)] E [input().split()[2:] for _ in range(N)] Q = [0] Q [0] 0 L = [0] + [-1]*N L [0] + [-1]*N [0] 0 [-1]*N [-1] -1 N frag = [1] + [0]*N frag [1] + [0]*N [1] 1 [0]*N [0] 0 N def func(ide):
    global Q
    for i in E[ide]:
        i = int(i) - 1
        if frag[i] != 1:frag[i] = 1;L[i] = L[ide] +1 ;Q.append(i)
     func global Q for i in E[ide]:
        i = int(i) - 1
        if frag[i] != 1:frag[i] = 1;L[i] = L[ide] +1 ;Q.append(i)
     i E[ide] E ide i = int(i) - 1 i int(i) - 1 int(i) int i 1 if frag[i] != 1:frag[i] = 1;L[i] = L[ide] +1 ;Q.append(i)
     frag[i] != 1 frag[i] frag i 1 ide ide while Q:top = Q.pop(0);func(top) Q for i in range(N):print(i + 1 ,int(L[i])) i range(N) range N Q = [0] [0] Q N= int(input()) int(input()) N L = [0] + [-1]*N [0] + [-1]*N L def func(ide):
    global Q
    for i in E[ide]:
        i = int(i) - 1
        if frag[i] != 1:frag[i] = 1;L[i] = L[ide] +1 ;Q.append(i)
     def func(ide):
    global Q
    for i in E[ide]:
        i = int(i) - 1
        if frag[i] != 1:frag[i] = 1;L[i] = L[ide] +1 ;Q.append(i)
     func E = [input().split()[2:] for _ in range(N)] [input().split()[2:] for _ in range(N)] E frag = [1] + [0]*N [1] + [0]*N frag
N= int(input())
E = [input().split()[2:] for _ in range(N)]
Q = [0]
L = [0] + [-1]*N
frag = [1] + [0]*N
def func(ide):
    global Q
    for i in E[ide]:
        i = int(i) - 1
        if frag[i] != 1:frag[i] = 1;L[i] = L[ide] +1 ;Q.append(i)
    

while Q:top = Q.pop(0);func(top)

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

