from collections import deque

N = int(input())
E = [None] * (N+1)
for _ in range(N):
    u, k, *vs = list(map(int, input().split()))
    E[u] = vs

d = [-1] * (N+1)
d[1] = 0
q = deque([(1, 0)])
while q:
    v, c = q.popleft()
    for u in E[v]:
        if d[u] < 0:
            d[u] = c+1
            q.append((u, c+1))

for i in range(1, N+1):
    print(i, d[i]) from collections import deque N = int(input()) N int(input()) int input() input E = [None] * (N+1) E [None] * (N+1) [None] None N+1 N 1 for _ in range(N):
    u, k, *vs = list(map(int, input().split()))
    E[u] = vs _ range(N) range N u, k, *vs = list(map(int, input().split())) u list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split k *vs vs E[u] = vs E[u] E u vs d = [-1] * (N+1) d [-1] * (N+1) [-1] -1 N+1 N 1 d[1] = 0 d[1] d 1 0 q = deque([(1, 0)]) q deque([(1, 0)]) deque [(1, 0)] (1, 0) 1 0 while q:
    v, c = q.popleft()
    for u in E[v]:
        if d[u] < 0:
            d[u] = c+1
            q.append((u, c+1)) q v, c = q.popleft() v q.popleft() q.popleft q popleft c for u in E[v]:
        if d[u] < 0:
            d[u] = c+1
            q.append((u, c+1)) u E[v] E v if d[u] < 0:
            d[u] = c+1
            q.append((u, c+1)) d[u] < 0 d[u] d u 0 d[u] = c+1 d[u] d u c+1 c 1 q.append((u, c+1)) q.append q append (u, c+1) u c+1 c 1 for i in range(1, N+1):
    print(i, d[i]) i range(1, N+1) range 1 N+1 N 1 print(i, d[i]) print i d[i] d i k, *vs = list(map(int, input().split())) list(map(int, input().split())) k c = q.popleft() q.popleft() c u, k, *vs = list(map(int, input().split())) list(map(int, input().split())) u d = [-1] * (N+1) [-1] * (N+1) d N = int(input()) int(input()) N E = [None] * (N+1) [None] * (N+1) E q = deque([(1, 0)]) deque([(1, 0)]) q v, c = q.popleft() q.popleft() v
from collections import deque

N = int(input())
E = [None] * (N+1)
for _ in range(N):
    u, k, *vs = list(map(int, input().split()))
    E[u] = vs

d = [-1] * (N+1)
d[1] = 0
q = deque([(1, 0)])
while q:
    v, c = q.popleft()
    for u in E[v]:
        if d[u] < 0:
            d[u] = c+1
            q.append((u, c+1))

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