import collections
N = int(input())
P = [[0 for _ in range(N)] for _ in range(N)] 
for i in range(N):
    u,k,*varray = map(int,input().split()) # u,k は数, varray は配列
    for v in varray:
        P[u-1][v-1] = 1    

D = [-1 for _ in range(N)]
D[0] = 0 # 始点への距離は 0, 他の距離は-1
Q = collections.deque()
Q.append(0)
while len(Q) > 0:
    c = Q.popleft()
    for i in range(N):
        if P[c][i]==1 and D[i]==-1:
            D[i] = D[c]+1
            Q.append(i)
for v in range(N):
    print(v+1, D[v])          import collections collections N = int(input()) N int(input()) int input() input [0 for _ in range(N)] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [0 for _ in range(N)] P = [[0 for _ in range(N)] for _ in range(N)] P [[0 for _ in range(N)] for _ in range(N)] for i in range(N):
    u,k,*varray = map(int,input().split()) # u,k は数, varray は配列
    for v in varray:
        P[u-1][v-1] = 1     i range(N) range N u,k,*varray = map(int,input().split()) u map(int,input().split()) map int input().split() ().split () input split k *varray varray for v in varray:
        P[u-1][v-1] = 1     v varray P[u-1][v-1] = 1 P[u-1][v-1] [u-1] P u-1 u 1 v-1 v 1 1 -1 for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) -1 D = [-1 for _ in range(N)] D [-1 for _ in range(N)] D[0] = 0 D[0] D 0 0 Q = collections.deque() Q collections.deque() collections.deque collections deque Q.append(0) Q.append Q append 0 while len(Q) > 0:
    c = Q.popleft()
    for i in range(N):
        if P[c][i]==1 and D[i]==-1:
            D[i] = D[c]+1
            Q.append(i) len(Q) > 0 len(Q) len Q 0 c = Q.popleft() c Q.popleft() Q.popleft Q popleft for i in range(N):
        if P[c][i]==1 and D[i]==-1:
            D[i] = D[c]+1
            Q.append(i) i range(N) range N if P[c][i]==1 and D[i]==-1:
            D[i] = D[c]+1
            Q.append(i) P[c][i]==1 and D[i]==-1 P[c][i]==1 P[c][i] [c] P c i 1 D[i]==-1 D[i] D i -1 D[i] = D[c]+1 D[i] D i D[c]+1 D[c] D c 1 Q.append(i) Q.append Q append i for v in range(N):
    print(v+1, D[v])          v range(N) range N print(v+1, D[v]) print v+1 v 1 D[v] D v D = [-1 for _ in range(N)] [-1 for _ in range(N)] D Q = collections.deque() collections.deque() Q c = Q.popleft() Q.popleft() c u,k,*varray = map(int,input().split()) map(int,input().split()) u N = int(input()) int(input()) N P = [[0 for _ in range(N)] for _ in range(N)] [[0 for _ in range(N)] for _ in range(N)] P k,*varray = map(int,input().split()) map(int,input().split()) k
import collections
N = int(input())
P = [[0 for _ in range(N)] for _ in range(N)] 
for i in range(N):
    u,k,*varray = map(int,input().split()) # u,k は数, varray は配列
    for v in varray:
        P[u-1][v-1] = 1    

D = [-1 for _ in range(N)]
D[0] = 0 # 始点への距離は 0, 他の距離は-1
Q = collections.deque()
Q.append(0)
while len(Q) > 0:
    c = Q.popleft()
    for i in range(N):
        if P[c][i]==1 and D[i]==-1:
            D[i] = D[c]+1
            Q.append(i)
for v in range(N):
    print(v+1, D[v])         
