def makearray()
  $n = gets.to_i
  $a = []
  $b = []
  for k in 0..$n-1
    $b[k] = []
    for l in 0..$n+1
      $b[k][l] = 0
    end
  end
  for i in 0..$n-1
    $a[i] = gets.split(' ').map(&:to_i)
    if $a[i][1] > 0
      for j in 2..$a[i][1]+1
        c = $a[i][j] - 1
        $b[i][c] = 1
      end
    end
  end
end

makearray()
Q = [0]
D = Array.new($n, -1)
D[0] = 0
$b[0][$n] = 1
while Q.size > 0
  c = Q.shift
  for i in 0..$n-1
    if $b[c][i] == 1 && $b[i][$n] == 0
      D[i] = D[c] + 1
      $b[i][$n] = 1
      Q << i
    end
  end
end
for i in 0..$n-1
  print i+1
  print ' '
  puts D[i]
end