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: N = int(input())
  List = [[] for i in range(N + 1)]
  for i in range(N):
      l = list(map(int, input().split()))
      List[l[0]] = l[2:]
  # print(List)
  D = [10**9 for i in range(N + 1)]
  
  Q = [[0, 1]]
  for i in range(10**9):
      if len(Q) == i:
          break
      if D[Q[i][1]] == 10**9:
          D[Q[i][1]] = Q[i][0]
          for j in List[Q[i][1]]:
              if D[j] == 10**9:
                  Q.append([Q[i][0] + 1, j])
  for i in range(1, N + 1):
      if D[i] == 10**9:
          print(i, -1)
      else:
          print(i, 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"}]