N = gets.to_i
G = (1..N).map{ Array.new(N, 0) }
N.times do
  u, k, *v = gets.split(' ').map(&:to_i)
  v.each do |vi|
    G[u - 1][vi - 1] = 1
  end
end

Q = [0] #?§????0?????\??£????????\???
D = Array.new(N, -1)
D[0] = 0 #?§???????????????¢???0??????????????¢???-1??¨????????????

while Q.size > 0
  cur = Q.shift
  (0..N-1).each do |dst|
    if G[cur][dst] == 1 && D[dst] == -1
      D[dst] = D[cur] + 1
      Q < dst
    end
  end
end

(0..N-1).each do |id|
  puts "#{id + 1} #{D[id]}"
end



# g.each do |r|
#   puts r.join(" ")
# end