from collections import deque
n=int(input())
E=[0]*n
for _ in range(n):
    u,k,*V=map(int,input().split())
    E[u-1]=V
d=[-1]*n
d[0]=0
todo=deque([1])
while todo:
    now=todo.popleft()
    for v in E[now-1]:
        if d[v-1]==-1:
            todo.append(v)
            d[v-1]=d[now-1]+1
for i in range(n):
    print(i+1,d[i]) from collections import deque n=int(input()) n int(input()) int input() input E=[0]*n E [0]*n [0] 0 n for _ in range(n):
    u,k,*V=map(int,input().split())
    E[u-1]=V _ range(n) range n u,k,*V=map(int,input().split()) u map(int,input().split()) map int input().split() ().split () input split k *V V E[u-1]=V E[u-1] E u-1 u 1 V d=[-1]*n d [-1]*n [-1] -1 n d[0]=0 d[0] d 0 0 todo=deque([1]) todo deque([1]) deque [1] 1 while todo:
    now=todo.popleft()
    for v in E[now-1]:
        if d[v-1]==-1:
            todo.append(v)
            d[v-1]=d[now-1]+1 todo now=todo.popleft() now todo.popleft() todo.popleft todo popleft for v in E[now-1]:
        if d[v-1]==-1:
            todo.append(v)
            d[v-1]=d[now-1]+1 v E[now-1] E now-1 now 1 if d[v-1]==-1:
            todo.append(v)
            d[v-1]=d[now-1]+1 d[v-1]==-1 d[v-1] d v-1 v 1 -1 todo.append(v) todo.append todo append v d[v-1]=d[now-1]+1 d[v-1] d v-1 v 1 d[now-1]+1 d[now-1] d now-1 now 1 1 for i in range(n):
    print(i+1,d[i]) i range(n) range n print(i+1,d[i]) print i+1 i 1 d[i] d i n=int(input()) int(input()) n now=todo.popleft() todo.popleft() now k,*V=map(int,input().split()) map(int,input().split()) k d=[-1]*n [-1]*n d E=[0]*n [0]*n E u,k,*V=map(int,input().split()) map(int,input().split()) u todo=deque([1]) deque([1]) todo
from collections import deque
n=int(input())
E=[0]*n
for _ in range(n):
    u,k,*V=map(int,input().split())
    E[u-1]=V
d=[-1]*n
d[0]=0
todo=deque([1])
while todo:
    now=todo.popleft()
    for v in E[now-1]:
        if d[v-1]==-1:
            todo.append(v)
            d[v-1]=d[now-1]+1
for i in range(n):
    print(i+1,d[i])
