#encoding: utf-8

$map = []
$vis = [false] * 100
$depth = [-1] * 100
$vis = [false] * 100
def build_map
  $n = gets.rstrip.to_i
  $map = []
  $n.times { $map << [0] * $n}
  (1..$n).each do |node|
    arr = gets.rstrip.split(/\s/).map(&:to_i)
    u, k = arr[0], arr[1]
    node = arr[2..-1]
    node.each { |v| $map[u - 1][v - 1] = 1}
  end
end

def bfs(x)
  $depth[x] = 0
  que = [x]
  $vis[x] = true
  while not que.empty?
    u, que = que.first, que.drop(1)
    $map[u].each_with_index do |node, idx|
      if node == 1 and not $vis[idx]
        $depth[idx] = $depth[u] + 1
        $vis[idx] = true
        que << idx
      end
    end
  end
end

def solve
  build_map
  bfs(0)
end

solve

(0..$n - 1).each do |node|
  puts "#{node + 1} #{$depth[node]}"
end