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

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

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

