import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N = int(input())
ukv = [list(map(int, input().split())) for _ in range(N)]
dist = [-1]*N
dist[0] = 0

deq = deque()
#deq.append(ukv[0][2:])
deq.append([1])

step = 0
while deq[0]:
#    print('deq:', deq)
    nextvs = []
    currvs = deq.popleft()
    for v in currvs:
        for nv in ukv[v-1][2:]:
            if dist[nv-1] == -1:
                dist[nv-1] = step+1
                nextvs.append(nv)
    deq.append(nextvs)
    step += 1

res = [[val1, val2] for val1, val2 in zip(range(1, N+1), dist)]
for a in res:
    print(*a)





 import sys, math sys math from itertools import permutations, combinations from collections import defaultdict, Counter, deque from math import factorial from bisect import bisect_left sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 enu = enumerate enu enumerate MOD = 10**9+7 MOD 10**9+7 10**9 10 9 7 def input(): return sys.stdin.readline()[:-1] input def pri(x): print('\n'.join(map(str, x))) pri x x N = int(input()) N int(input()) int input() input list(map(int, input().split())) for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ukv = [list(map(int, input().split())) for _ in range(N)] ukv [list(map(int, input().split())) for _ in range(N)] dist = [-1]*N dist [-1]*N [-1] -1 N dist[0] = 0 dist[0] dist 0 0 deq = deque() deq deque() deque deq.append([1]) deq.append deq append [1] 1 step = 0 step 0 while deq[0]:
#    print('deq:', deq)
    nextvs = []
    currvs = deq.popleft()
    for v in currvs:
        for nv in ukv[v-1][2:]:
            if dist[nv-1] == -1:
                dist[nv-1] = step+1
                nextvs.append(nv)
    deq.append(nextvs)
    step += 1 deq[0] deq 0 nextvs = [] nextvs [] currvs = deq.popleft() currvs deq.popleft() deq.popleft deq popleft for v in currvs:
        for nv in ukv[v-1][2:]:
            if dist[nv-1] == -1:
                dist[nv-1] = step+1
                nextvs.append(nv)
     v currvs for nv in ukv[v-1][2:]:
            if dist[nv-1] == -1:
                dist[nv-1] = step+1
                nextvs.append(nv)
     nv ukv[v-1][2:] [v-1] ukv v-1 v 1 2: 2 if dist[nv-1] == -1:
                dist[nv-1] = step+1
                nextvs.append(nv)
     dist[nv-1] == -1 dist[nv-1] dist nv-1 nv 1 -1 dist[nv-1] = step+1 dist[nv-1] dist nv-1 nv 1 step+1 step 1 nextvs.append(nv) nextvs.append nextvs append nv deq.append(nextvs) deq.append deq append nextvs step += 1 step 1 [val1, val2] for val1, val2 in zip(range(1, N+1), dist) for val1, val2 in zip(range(1, N+1), dist) val1 val2 zip(range(1, N+1), dist) zip range(1, N+1) range 1 N+1 N 1 dist for val1, val2 in zip(range(1, N+1), dist) [val1, val2] val1 val2 res = [[val1, val2] for val1, val2 in zip(range(1, N+1), dist)] res [[val1, val2] for val1, val2 in zip(range(1, N+1), dist)] for a in res:
    print(*a) a res print(*a) print *a a step += 1 1 step dist = [-1]*N [-1]*N dist res = [[val1, val2] for val1, val2 in zip(range(1, N+1), dist)] [[val1, val2] for val1, val2 in zip(range(1, N+1), dist)] res N = int(input()) int(input()) N deq = deque() deque() deq nextvs = [] [] nextvs MOD = 10**9+7 10**9+7 MOD step = 0 0 step def pri(x): print('\n'.join(map(str, x))) def pri(x): print('\n'.join(map(str, x))) pri ukv = [list(map(int, input().split())) for _ in range(N)] [list(map(int, input().split())) for _ in range(N)] ukv currvs = deq.popleft() deq.popleft() currvs def input(): return sys.stdin.readline()[:-1] def input(): return sys.stdin.readline()[:-1] input enu = enumerate enumerate enu
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N = int(input())
ukv = [list(map(int, input().split())) for _ in range(N)]
dist = [-1]*N
dist[0] = 0

deq = deque()
#deq.append(ukv[0][2:])
deq.append([1])

step = 0
while deq[0]:
#    print('deq:', deq)
    nextvs = []
    currvs = deq.popleft()
    for v in currvs:
        for nv in ukv[v-1][2:]:
            if dist[nv-1] == -1:
                dist[nv-1] = step+1
                nextvs.append(nv)
    deq.append(nextvs)
    step += 1

res = [[val1, val2] for val1, val2 in zip(range(1, N+1), dist)]
for a in res:
    print(*a)






