output_description: For each vertex $u$, print $id$ and $d$ in a line. $id$ is ID of vertex $u$
  and $d$ is the distance from vertex $1$ to vertex $u$. If there are no path
  from vertex $1$ to vertex $u$, print -1 as the shortest distance. Print in
  order of IDs.
input_description: In the first line, an integer $n$ denoting the number of vertices, is given.
  In the next $n$ lines, adjacent lists of vertex $u$ are given in the following
  format:
  
  $u$ $k$ $v_1$ $v_2$ ... $v_k$
  
  $u$ is ID of the vertex and $k$ denotes its degree.$v_i$ are IDs of vertices
  adjacent to $u$.
attempt: from sys import stdin
  
  X = [0 for i in range(100)]
  d = [0 for i in range(100)]
  G = [[0 for i in range(100)] for i in range(100)]
  queue = [0 for i in range(100)]
  
  t = 0
  head = 0
  tail = 0
  
  
  def BFS(i):
      global head
      for j in range(n):
          if G[i][j] == 1 and d[j] == 0:
              d[j] = d[i] + 1
              queue[head] = j
              head += 1
  
  
  def tailQ():
      global tail
      tail += 1
      return queue[tail - 1]
  
  
  n = int(input())
  for i in range(n):
      X[i] = stdin.readline().strip().split()
  
  
  for i in range(n):
      for j in range(int(X[i][1])):
          G[int(X[i][0]) - 1][int(X[i][j + 2]) - 1] = 1
  
  BFS(0)
  while head - tail != 0:
      BFS(tailQ())
  
  for i in range(n):
      print(i + 1, d[i])
  
problem_description: Breadth First Search
  
  Write a program which reads an directed graph $G = (V, E)$, and finds the
  shortest distance from vertex $1$ to each vertex (the number of edges in the
  shortest path). Vertices are identified by IDs $1, 2, ... n$.
samples: [{"input": "4\n    1 2 2 4\n    2 1 4\n    3 0\n    4 1 3", "output": "1 0\n    2 1\n    3 2\n    4 1"}]