# coding: utf-8
#require "pry"
topnum = gets.to_i
$arr = []
$res = Array.new(topnum)
for topnum in 0..(topnum-1)
  inputNum = gets.chomp.split(' ').map(&:to_i)
  inputNum.delete_at(1)
  arrIndex = inputNum.shift
  $arr[arrIndex-1] = inputNum
end

$res[0] = 0
def breadth_first_search(topArr,d)
  if topArr.empty?
    return
  end
  d = $res.compact.max + 1
  topArr.each{ |i| 
    if $res[i-1] == nil
      $res[i-1] = d
    end
  }

  topArr.each{ |i| 
    if $res.compact.inject(:+) > 2
      return
    end
    breadth_first_search($arr[i-1],d) 
  }
end
breadth_first_search($arr[0],0)
$res.map!{ |i| 
  if i == nil
    i = -1
  else
    i = i
  end 
}

$res.length.times { |i| 
  print (i+1)
  print ' '
  puts $res[i] 
}