n = int(input())

A = [[] for i in range(n)]

for i in range(n):
  A[i] = list(map(int, input().split()))

f_inf = float("inf")
B = [[f_inf for i in range(2)] for j in range(n)]
B[0][1] = 0

for i in range(n):
  B[i][0] = i+1

def dbs(a):
  global order
  l = len(A[a-1])-2
  if l:
    for i in range(l):
      depth = B[a-1][1]+1
      b = A[a-1][i+2]
      if not b in order or depth < B[b-1][1]:
        B[b-1][1] = depth
        order.append(b)
        dbs(b)

order = [1]
dbs(1)

for i in range(n):
  if B[i][1] == f_inf:
    B[i][1] = -1
  print(" ".join(map(str, B[i]))) n = int(input()) n int(input()) int input() input [] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [] A = [[] for i in range(n)] A [[] for i in range(n)] for i in range(n):
  A[i] = list(map(int, input().split())) i range(n) range n A[i] = list(map(int, input().split())) A[i] A i list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split f_inf = float("inf") f_inf float("inf") float "inf" [f_inf for i in range(2)] for j in range(n) for j in range(n) j range(n) range n for j in range(n) [f_inf for i in range(2)] B = [[f_inf for i in range(2)] for j in range(n)] B [[f_inf for i in range(2)] for j in range(n)] B[0][1] = 0 B[0][1] [0] B 0 1 0 for i in range(n):
  B[i][0] = i+1 i range(n) range n B[i][0] = i+1 B[i][0] [i] B i 0 i+1 i 1 def dbs(a):
  global order
  l = len(A[a-1])-2
  if l:
    for i in range(l):
      depth = B[a-1][1]+1
      b = A[a-1][i+2]
      if not b in order or depth < B[b-1][1]:
        B[b-1][1] = depth
        order.append(b)
        dbs(b) dbs global order l = len(A[a-1])-2 l len(A[a-1])-2 len(A[a-1]) len A[a-1] A a-1 a 1 2 if l:
    for i in range(l):
      depth = B[a-1][1]+1
      b = A[a-1][i+2]
      if not b in order or depth < B[b-1][1]:
        B[b-1][1] = depth
        order.append(b)
        dbs(b) l for i in range(l):
      depth = B[a-1][1]+1
      b = A[a-1][i+2]
      if not b in order or depth < B[b-1][1]:
        B[b-1][1] = depth
        order.append(b)
        dbs(b) i range(l) range l depth = B[a-1][1]+1 depth B[a-1][1]+1 B[a-1][1] [a-1] B a-1 a 1 1 1 b = A[a-1][i+2] b A[a-1][i+2] [a-1] A a-1 a 1 i+2 i 2 if not b in order or depth < B[b-1][1]:
        B[b-1][1] = depth
        order.append(b)
        dbs(b) not b in order or depth < B[b-1][1] not b in order b in order b order depth < B[b-1][1] depth B[b-1][1] [b-1] B b-1 b 1 1 B[b-1][1] = depth B[b-1][1] [b-1] B b-1 b 1 1 depth order.append(b) order.append order append b dbs(b) dbs b a a order = [1] order [1] 1 dbs(1) dbs 1 for i in range(n):
  if B[i][1] == f_inf:
    B[i][1] = -1
  print(" ".join(map(str, B[i]))) i range(n) range n if B[i][1] == f_inf:
    B[i][1] = -1
   B[i][1] == f_inf B[i][1] [i] B i 1 f_inf B[i][1] = -1 B[i][1] [i] B i 1 -1 print(" ".join(map(str, B[i]))) print " ".join(map(str, B[i])) " ".join " " join map(str, B[i]) map str B[i] B i n = int(input()) int(input()) n B = [[f_inf for i in range(2)] for j in range(n)] [[f_inf for i in range(2)] for j in range(n)] B f_inf = float("inf") float("inf") f_inf def dbs(a):
  global order
  l = len(A[a-1])-2
  if l:
    for i in range(l):
      depth = B[a-1][1]+1
      b = A[a-1][i+2]
      if not b in order or depth < B[b-1][1]:
        B[b-1][1] = depth
        order.append(b)
        dbs(b) def dbs(a):
  global order
  l = len(A[a-1])-2
  if l:
    for i in range(l):
      depth = B[a-1][1]+1
      b = A[a-1][i+2]
      if not b in order or depth < B[b-1][1]:
        B[b-1][1] = depth
        order.append(b)
        dbs(b) dbs order = [1] [1] order A = [[] for i in range(n)] [[] for i in range(n)] A
n = int(input())

A = [[] for i in range(n)]

for i in range(n):
  A[i] = list(map(int, input().split()))

f_inf = float("inf")
B = [[f_inf for i in range(2)] for j in range(n)]
B[0][1] = 0

for i in range(n):
  B[i][0] = i+1

def dbs(a):
  global order
  l = len(A[a-1])-2
  if l:
    for i in range(l):
      depth = B[a-1][1]+1
      b = A[a-1][i+2]
      if not b in order or depth < B[b-1][1]:
        B[b-1][1] = depth
        order.append(b)
        dbs(b)

order = [1]
dbs(1)

for i in range(n):
  if B[i][1] == f_inf:
    B[i][1] = -1
  print(" ".join(map(str, B[i])))
