import collections

N = int(input())
G = [[0 for _ in range(N)] for _ in range(N)]
for i in range(N):
    u,k,*varray = map(int,input().split())
    for v in varray:
        G[u-1][v-1] = 1
        
D = [-1 for _ in range(N)]
D[0] = 0
Q = collections.deque()
Q.append(0)
while len(Q) > 0:
    # print("bfs",Q)
    cur = Q.popleft()
    for dst in range(N):
        if G[cur][dst] == 1 and D[dst] == -1:
            D[dst] = D[cur] + 1
            Q.append(dst)
for v in range(N):
    print(v+1, D[v])
            

# 順番を書こう。落ち着け
# まずd=1の時→行列の一行目をみよう
# 1になっている列を探す→そいつらのDは全部2に変える
# プラスしてそいつらのしもべたちを3にする
#  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)] G = [[0 for _ in range(N)] for _ in range(N)] G [[0 for _ in range(N)] for _ in range(N)] for i in range(N):
    u,k,*varray = map(int,input().split())
    for v in varray:
        G[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:
        G[u-1][v-1] = 1
         v varray G[u-1][v-1] = 1 G[u-1][v-1] [u-1] G 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:
    # print("bfs",Q)
    cur = Q.popleft()
    for dst in range(N):
        if G[cur][dst] == 1 and D[dst] == -1:
            D[dst] = D[cur] + 1
            Q.append(dst) len(Q) > 0 len(Q) len Q 0 cur = Q.popleft() cur Q.popleft() Q.popleft Q popleft for dst in range(N):
        if G[cur][dst] == 1 and D[dst] == -1:
            D[dst] = D[cur] + 1
            Q.append(dst) dst range(N) range N if G[cur][dst] == 1 and D[dst] == -1:
            D[dst] = D[cur] + 1
            Q.append(dst) G[cur][dst] == 1 and D[dst] == -1 G[cur][dst] == 1 G[cur][dst] [cur] G cur dst 1 D[dst] == -1 D[dst] D dst -1 D[dst] = D[cur] + 1 D[dst] D dst D[cur] + 1 D[cur] D cur 1 Q.append(dst) Q.append Q append dst for v in range(N):
    print(v+1, D[v])
            

# 順番を書こう。落ち着け
# まずd=1の時→行列の一行目をみよう
# 1になっている列を探す→そいつらのDは全部2に変える
# プラスしてそいつらのしもべたちを3にする
#  v range(N) range N print(v+1, D[v]) print v+1 v 1 D[v] D v G = [[0 for _ in range(N)] for _ in range(N)] [[0 for _ in range(N)] for _ in range(N)] G k,*varray = map(int,input().split()) map(int,input().split()) k cur = Q.popleft() Q.popleft() cur u,k,*varray = map(int,input().split()) map(int,input().split()) u D = [-1 for _ in range(N)] [-1 for _ in range(N)] D N = int(input()) int(input()) N Q = collections.deque() collections.deque() Q
import collections

N = int(input())
G = [[0 for _ in range(N)] for _ in range(N)]
for i in range(N):
    u,k,*varray = map(int,input().split())
    for v in varray:
        G[u-1][v-1] = 1
        
D = [-1 for _ in range(N)]
D[0] = 0
Q = collections.deque()
Q.append(0)
while len(Q) > 0:
    # print("bfs",Q)
    cur = Q.popleft()
    for dst in range(N):
        if G[cur][dst] == 1 and D[dst] == -1:
            D[dst] = D[cur] + 1
            Q.append(dst)
for v in range(N):
    print(v+1, D[v])
            

# 順番を書こう。落ち着け
# まずd=1の時→行列の一行目をみよう
# 1になっている列を探す→そいつらのDは全部2に変える
# プラスしてそいつらのしもべたちを3にする
# 
