import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


N = int(input())

edge = {}
for _ in range(N):
    tmp = inpl()
    u, k = tmp[:2]
    edge[u] = tmp[2:]

d = {i: -1 for i in range(1, N + 1)}
d[1] = 0
Q = deque()
Q.append(1)
while Q:
    v = Q.popleft()
    for nv in edge[v]:
        if d[nv] != -1:
            continue
        d[nv] = d[v] + 1
        Q.append(nv)

for i in range(1, N + 1):
    print(i, d[i])
 import sys sys from collections import deque input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline sys.setrecursionlimit(2 * 10**6) sys.setrecursionlimit sys setrecursionlimit 2 * 10**6 2 10**6 10 6 def inpl():
    return list(map(int, input().split())) inpl return list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split N = int(input()) N int(input()) int input() input edge = {} edge {} for _ in range(N):
    tmp = inpl()
    u, k = tmp[:2]
    edge[u] = tmp[2:] _ range(N) range N tmp = inpl() tmp inpl() inpl u, k = tmp[:2] u tmp[:2] tmp :2 2 k edge[u] = tmp[2:] edge[u] edge u tmp[2:] tmp 2: 2 i: -1 for i in range(1, N + 1) for i in range(1, N + 1) i range(1, N + 1) range 1 N + 1 N 1 for i in range(1, N + 1) i -1 d = {i: -1 for i in range(1, N + 1)} d {i: -1 for i in range(1, N + 1)} d[1] = 0 d[1] d 1 0 Q = deque() Q deque() deque Q.append(1) Q.append Q append 1 while Q:
    v = Q.popleft()
    for nv in edge[v]:
        if d[nv] != -1:
            continue
        d[nv] = d[v] + 1
        Q.append(nv) Q v = Q.popleft() v Q.popleft() Q.popleft Q popleft for nv in edge[v]:
        if d[nv] != -1:
            continue
        d[nv] = d[v] + 1
        Q.append(nv) nv edge[v] edge v if d[nv] != -1:
            continue
         d[nv] != -1 d[nv] d nv -1 continue d[nv] = d[v] + 1 d[nv] d nv d[v] + 1 d[v] d v 1 Q.append(nv) Q.append Q append nv 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 edge = {} {} edge def inpl():
    return list(map(int, input().split())) def inpl():
    return list(map(int, input().split())) inpl tmp = inpl() inpl() tmp d = {i: -1 for i in range(1, N + 1)} {i: -1 for i in range(1, N + 1)} d u, k = tmp[:2] tmp[:2] u input = sys.stdin.readline sys.stdin.readline input v = Q.popleft() Q.popleft() v k = tmp[:2] tmp[:2] k Q = deque() deque() Q N = int(input()) int(input()) N
import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


N = int(input())

edge = {}
for _ in range(N):
    tmp = inpl()
    u, k = tmp[:2]
    edge[u] = tmp[2:]

d = {i: -1 for i in range(1, N + 1)}
d[1] = 0
Q = deque()
Q.append(1)
while Q:
    v = Q.popleft()
    for nv in edge[v]:
        if d[nv] != -1:
            continue
        d[nv] = d[v] + 1
        Q.append(nv)

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

