n = int(input())

G = []
G.append([])
for i in range(n):
    v = list(map(int, input().split()))
    G.append(v[2:])

q = []
q.append(1)

checked = [False] * (n + 1)
checked[1] = True
d = [-1] * (n + 1)
d[1] = 0

while q:
    current = q.pop(0)
    for v in G[current]:
        if not checked[v]:
            q.append(v)
            d[v] = d[current] + 1
            checked[v] = True

for i in range(1, n + 1):
    print(i, d[i]) n = int(input()) n int(input()) int input() input G = [] G [] G.append([]) G.append G append [] for i in range(n):
    v = list(map(int, input().split()))
    G.append(v[2:]) i range(n) range n v = list(map(int, input().split())) v list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split G.append(v[2:]) G.append G append v[2:] v 2: 2 q = [] q [] q.append(1) q.append q append 1 checked = [False] * (n + 1) checked [False] * (n + 1) [False] False n + 1 n 1 checked[1] = True checked[1] checked 1 True d = [-1] * (n + 1) d [-1] * (n + 1) [-1] -1 n + 1 n 1 d[1] = 0 d[1] d 1 0 while q:
    current = q.pop(0)
    for v in G[current]:
        if not checked[v]:
            q.append(v)
            d[v] = d[current] + 1
            checked[v] = True q current = q.pop(0) current q.pop(0) q.pop q pop 0 for v in G[current]:
        if not checked[v]:
            q.append(v)
            d[v] = d[current] + 1
            checked[v] = True v G[current] G current if not checked[v]:
            q.append(v)
            d[v] = d[current] + 1
            checked[v] = True not checked[v] checked[v] checked v q.append(v) q.append q append v d[v] = d[current] + 1 d[v] d v d[current] + 1 d[current] d current 1 checked[v] = True checked[v] checked v True 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 v = list(map(int, input().split())) list(map(int, input().split())) v n = int(input()) int(input()) n current = q.pop(0) q.pop(0) current q = [] [] q checked = [False] * (n + 1) [False] * (n + 1) checked G = [] [] G d = [-1] * (n + 1) [-1] * (n + 1) d
n = int(input())

G = []
G.append([])
for i in range(n):
    v = list(map(int, input().split()))
    G.append(v[2:])

q = []
q.append(1)

checked = [False] * (n + 1)
checked[1] = True
d = [-1] * (n + 1)
d[1] = 0

while q:
    current = q.pop(0)
    for v in G[current]:
        if not checked[v]:
            q.append(v)
            d[v] = d[current] + 1
            checked[v] = True

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