n = gets.to_i
m = Array.new(n) # adjacency matrix
for i in 0..n-1
  m[i] = Array.new(n,0)
end
for i in 0..n-1
  temp = gets.chomp.split(" ").map(&:to_i)
  if temp[1] != 0
    for j in 0..temp[1]-1
      m[i][temp[j+2]-1] = 1
    end
  end
end

q = [0] # queue
d = Array.new(n,-1)
d[0] = 0
while q.length > 0
  #p ["debug", q]
  cur = q.shift
  (0..n-1).each do |dst|
    if m[cur][dst] == 1 && d[dst] == -1
      d[dst] = d[cur] + 1
      q << dst
    end
  end
end

for i in 0..n-1
  print i+1, " ", d[i], "\n"
end