from collections import deque
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
d=deque()
d.append(1)
check=[0]*n
check[0]=1
ans=[0]*n
kyori=[0]*n
while len(d)!=0:
  v=d.popleft()
  for i in l[v-1][2:]:
    if check[i-1]==0:
      check[i-1]=1
      ans[i-1]=(kyori[v-1]+1)
      kyori[i-1]=(kyori[v-1]+1)
      d.append(i)
for i in range(1,n):
  if ans[i]==0:
    ans[i]=-1
for i in range(n):
    print(i+1,ans[i]) from collections import deque n=int(input()) n int(input()) int input() input list(map(int,input().split())) for i in range(n) for i in range(n) i range(n) range n for i in range(n) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split l=[list(map(int,input().split())) for i in range(n)] l [list(map(int,input().split())) for i in range(n)] d=deque() d deque() deque d.append(1) d.append d append 1 check=[0]*n check [0]*n [0] 0 n check[0]=1 check[0] check 0 1 ans=[0]*n ans [0]*n [0] 0 n kyori=[0]*n kyori [0]*n [0] 0 n while len(d)!=0:
  v=d.popleft()
  for i in l[v-1][2:]:
    if check[i-1]==0:
      check[i-1]=1
      ans[i-1]=(kyori[v-1]+1)
      kyori[i-1]=(kyori[v-1]+1)
      d.append(i) len(d)!=0 len(d) len d 0 v=d.popleft() v d.popleft() d.popleft d popleft for i in l[v-1][2:]:
    if check[i-1]==0:
      check[i-1]=1
      ans[i-1]=(kyori[v-1]+1)
      kyori[i-1]=(kyori[v-1]+1)
      d.append(i) i l[v-1][2:] [v-1] l v-1 v 1 2: 2 if check[i-1]==0:
      check[i-1]=1
      ans[i-1]=(kyori[v-1]+1)
      kyori[i-1]=(kyori[v-1]+1)
      d.append(i) check[i-1]==0 check[i-1] check i-1 i 1 0 check[i-1]=1 check[i-1] check i-1 i 1 1 ans[i-1]=(kyori[v-1]+1) ans[i-1] ans i-1 i 1 kyori[v-1]+1 kyori[v-1] kyori v-1 v 1 1 kyori[i-1]=(kyori[v-1]+1) kyori[i-1] kyori i-1 i 1 kyori[v-1]+1 kyori[v-1] kyori v-1 v 1 1 d.append(i) d.append d append i for i in range(1,n):
  if ans[i]==0:
    ans[i]=-1 i range(1,n) range 1 n if ans[i]==0:
    ans[i]=-1 ans[i]==0 ans[i] ans i 0 ans[i]=-1 ans[i] ans i -1 for i in range(n):
    print(i+1,ans[i]) i range(n) range n print(i+1,ans[i]) print i+1 i 1 ans[i] ans i d=deque() deque() d ans=[0]*n [0]*n ans check=[0]*n [0]*n check kyori=[0]*n [0]*n kyori l=[list(map(int,input().split())) for i in range(n)] [list(map(int,input().split())) for i in range(n)] l n=int(input()) int(input()) n v=d.popleft() d.popleft() v
from collections import deque
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
d=deque()
d.append(1)
check=[0]*n
check[0]=1
ans=[0]*n
kyori=[0]*n
while len(d)!=0:
  v=d.popleft()
  for i in l[v-1][2:]:
    if check[i-1]==0:
      check[i-1]=1
      ans[i-1]=(kyori[v-1]+1)
      kyori[i-1]=(kyori[v-1]+1)
      d.append(i)
for i in range(1,n):
  if ans[i]==0:
    ans[i]=-1
for i in range(n):
    print(i+1,ans[i])
