n = int(raw_input())
 
d = [99999 for i in range(n)]
G = [0 for i in range(n)]
M = [[0 for i in range(n)] for j in range(n)]
 
def BFS(s):
    for e in range(n):
        if M[s][e] == 1:
            if d[e] > d[s] + 1:
                d[e] = d[s]+1
                BFS(e)
 
for i in range(n):
    G = map(int, raw_input().split())
    for j in range(G[1]):
        M[G[0]-1][G[2+j]-1] = 1
 
d[0] = 0
for s in range(n):
        BFS(s)
for s in range(n):
    if d[s] == 99999:
        d[s] = -1
for s in range(n):
    print'{0} {1}'.format(s+1, d[s]) n = int(raw_input()) n int(raw_input()) int raw_input() raw_input 99999 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 99999 d = [99999 for i in range(n)] d [99999 for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 G = [0 for i in range(n)] G [0 for i in range(n)] [0 for i in range(n)] for j in range(n) for j in range(n) j range(n) range n for j in range(n) [0 for i in range(n)] M = [[0 for i in range(n)] for j in range(n)] M [[0 for i in range(n)] for j in range(n)] def BFS(s):
    for e in range(n):
        if M[s][e] == 1:
            if d[e] > d[s] + 1:
                d[e] = d[s]+1
                BFS(e)
  BFS for e in range(n):
        if M[s][e] == 1:
            if d[e] > d[s] + 1:
                d[e] = d[s]+1
                BFS(e)
  e range(n) range n if M[s][e] == 1:
            if d[e] > d[s] + 1:
                d[e] = d[s]+1
                BFS(e)
  M[s][e] == 1 M[s][e] [s] M s e 1 if d[e] > d[s] + 1:
                d[e] = d[s]+1
                BFS(e)
  d[e] > d[s] + 1 d[e] d e d[s] + 1 d[s] d s 1 d[e] = d[s]+1 d[e] d e d[s]+1 d[s] d s 1 BFS(e) BFS e s s for i in range(n):
    G = map(int, raw_input().split())
    for j in range(G[1]):
        M[G[0]-1][G[2+j]-1] = 1
  i range(n) range n G = map(int, raw_input().split()) G map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split for j in range(G[1]):
        M[G[0]-1][G[2+j]-1] = 1
  j range(G[1]) range G[1] G 1 M[G[0]-1][G[2+j]-1] = 1 M[G[0]-1][G[2+j]-1] [G[0]-1] M G[0]-1 G[0] G 0 1 G[2+j]-1 G[2+j] G 2+j 2 j 1 1 d[0] = 0 d[0] d 0 0 for s in range(n):
        BFS(s) s range(n) range n BFS(s) BFS s for s in range(n):
    if d[s] == 99999:
        d[s] = -1 s range(n) range n if d[s] == 99999:
        d[s] = -1 d[s] == 99999 d[s] d s 99999 d[s] = -1 d[s] d s -1 for s in range(n):
    print'{0} {1}'.format(s+1, d[s]) s range(n) range n print '{0} {1}'.format(s+1, d[s]) '{0} {1}'.format '{0} {1}' format s+1 s 1 d[s] d s G = [0 for i in range(n)] [0 for i in range(n)] G n = int(raw_input()) int(raw_input()) n M = [[0 for i in range(n)] for j in range(n)] [[0 for i in range(n)] for j in range(n)] M G = map(int, raw_input().split()) map(int, raw_input().split()) G d = [99999 for i in range(n)] [99999 for i in range(n)] d def BFS(s):
    for e in range(n):
        if M[s][e] == 1:
            if d[e] > d[s] + 1:
                d[e] = d[s]+1
                BFS(e)
  def BFS(s):
    for e in range(n):
        if M[s][e] == 1:
            if d[e] > d[s] + 1:
                d[e] = d[s]+1
                BFS(e)
  BFS
n = int(raw_input())
 
d = [99999 for i in range(n)]
G = [0 for i in range(n)]
M = [[0 for i in range(n)] for j in range(n)]
 
def BFS(s):
    for e in range(n):
        if M[s][e] == 1:
            if d[e] > d[s] + 1:
                d[e] = d[s]+1
                BFS(e)
 
for i in range(n):
    G = map(int, raw_input().split())
    for j in range(G[1]):
        M[G[0]-1][G[2+j]-1] = 1
 
d[0] = 0
for s in range(n):
        BFS(s)
for s in range(n):
    if d[s] == 99999:
        d[s] = -1
for s in range(n):
    print'{0} {1}'.format(s+1, d[s])