#! /usr/bin/ruby -w
# encoding: utf-8
#

def count_path(node, queue, checked, goal, count)
  next_step = []
  queue.each do |current|
    if current == goal
      return count
    else
      node[current].each do |n|
        if checked[n].nil?
          checked[n] = true
          next_step << n
        end
      end
    end
  end
  if next_step.empty?
    return -1
  else
    return count_path(node, next_step, checked, goal, count + 1)
  end
end

if __FILE__ == $0
  n = gets.to_i
  node = {}
  n.times {
    info = gets.split.map(&:to_i)
    node_num, adj = info[0], info[2..-1]
    node[node_num] = adj
  }

  n.times do |t|
    node_num = t + 1
    puts "#{node_num} #{count_path(node, [1], {}, node_num, 0)}"
  end
end
