#coding: utf-8
inf = 100000000
n = int(input())

List = [0] + [list(map(int,input().split())) for i in range(n)]
d = [inf for i in range(n+1)]
color = ["white" for i in range(n+1)]

s = 1
Q = [s]
d[s] = 0
color[s] = "gray"

while Q != []:
    q = Q.pop(0)
    k = List[q][1]
    for i in List[q][2:2+k]:
        if color[i] == "white":
            Q.append(i)
        d[i] = min(d[q] + 1, d[i])
    color[q] = "gray"


for i, dis in enumerate(d[1:], 1):
    if dis == inf:
        dis = -1
    print(i, dis)
 inf = 100000000 inf 100000000 n = int(input()) n int(input()) int input() input list(map(int,input().split())) for i in range(n) for i in range(n) i range(n) range n for i in range(n) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split List = [0] + [list(map(int,input().split())) for i in range(n)] List [0] + [list(map(int,input().split())) for i in range(n)] [0] 0 [list(map(int,input().split())) for i in range(n)] inf 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) inf d = [inf for i in range(n+1)] d [inf for i in range(n+1)] "white" 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) "white" color = ["white" for i in range(n+1)] color ["white" for i in range(n+1)] s = 1 s 1 Q = [s] Q [s] s d[s] = 0 d[s] d s 0 color[s] = "gray" color[s] color s "gray" while Q != []:
    q = Q.pop(0)
    k = List[q][1]
    for i in List[q][2:2+k]:
        if color[i] == "white":
            Q.append(i)
        d[i] = min(d[q] + 1, d[i])
    color[q] = "gray" Q != [] Q [] q = Q.pop(0) q Q.pop(0) Q.pop Q pop 0 k = List[q][1] k List[q][1] [q] List q 1 for i in List[q][2:2+k]:
        if color[i] == "white":
            Q.append(i)
        d[i] = min(d[q] + 1, d[i])
     i List[q][2:2+k] [q] List q 2:2+k 2 2+k 2 k if color[i] == "white":
            Q.append(i)
         color[i] == "white" color[i] color i "white" Q.append(i) Q.append Q append i d[i] = min(d[q] + 1, d[i]) d[i] d i min(d[q] + 1, d[i]) min d[q] + 1 d[q] d q 1 d[i] d i color[q] = "gray" color[q] color q "gray" for i, dis in enumerate(d[1:], 1):
    if dis == inf:
        dis = -1
    print(i, dis) i dis enumerate(d[1:], 1) enumerate d[1:] d 1: 1 1 if dis == inf:
        dis = -1
     dis == inf dis inf dis = -1 dis -1 print(i, dis) print i dis d = [inf for i in range(n+1)] [inf for i in range(n+1)] d q = Q.pop(0) Q.pop(0) q n = int(input()) int(input()) n s = 1 1 s dis = -1 -1 dis Q = [s] [s] Q k = List[q][1] List[q][1] k color = ["white" for i in range(n+1)] ["white" for i in range(n+1)] color List = [0] + [list(map(int,input().split())) for i in range(n)] [0] + [list(map(int,input().split())) for i in range(n)] List inf = 100000000 100000000 inf
#coding: utf-8
inf = 100000000
n = int(input())

List = [0] + [list(map(int,input().split())) for i in range(n)]
d = [inf for i in range(n+1)]
color = ["white" for i in range(n+1)]

s = 1
Q = [s]
d[s] = 0
color[s] = "gray"

while Q != []:
    q = Q.pop(0)
    k = List[q][1]
    for i in List[q][2:2+k]:
        if color[i] == "white":
            Q.append(i)
        d[i] = min(d[q] + 1, d[i])
    color[q] = "gray"


for i, dis in enumerate(d[1:], 1):
    if dis == inf:
        dis = -1
    print(i, dis)

