# bfs.rb
#ALDS1_11_C

$n = STDIN.gets.split[0].to_i
$rinsetu = Array.new(101).map{Array.new(101,0)}
$d = Array.new(101,9999999)
$q = Array.new

1.upto($n){|i|
  s = STDIN.gets.split
  u = s[0].to_i
  k = s[1].to_i
  0.upto(k-1){|j| 
    v = s[2+j].to_i
    $rinsetu[u][v] = 1
  }
}

$q << 1
$idx = 0
$d[1]=0

while $idx < $q.length
  node = $q[$idx]
#  printf("node=%d\n",node)
  1.upto($n) {|i|
    if i != node && $rinsetu[node][i]==1 && $d[i] > 1+$d[node]
      $d[i] = 1+$d[node] 
      $q << i
    end
  }
  $idx += 1
end

1.upto($n) {|i|
  if $d[i] != 9999999 
    printf("%d %d\n",i,$d[i])
  else
    printf("%d -1\n",i)
  end
}