import queue,sys
N=int(input())
M=[list(map(int,e.split()[2:]))for e in sys.stdin]
q=queue.Queue();q.put(0)
d=[-1]*N;d[0]=0
while q.qsize()>0:
 u=q.get()
 for v in M[u]:
  v-=1
  if d[v]<0:d[v]=d[u]+1;q.put(v)
for i in range(N):print(i+1,d[i]) import queue,sys queue sys N=int(input()) N int(input()) int input() input list(map(int,e.split()[2:]))for e in sys.stdin for e in sys.stdin e sys.stdin sys stdin for e in sys.stdin list(map(int,e.split()[2:])) list map(int,e.split()[2:]) map int e.split()[2:] e.split() e.split e split 2: 2 M=[list(map(int,e.split()[2:]))for e in sys.stdin] M [list(map(int,e.split()[2:]))for e in sys.stdin] q=queue.Queue() q queue.Queue() queue.Queue queue Queue q.put(0) q.put q put 0 d=[-1]*N d [-1]*N [-1] -1 N d[0]=0 d[0] d 0 0 while q.qsize()>0:
 u=q.get()
 for v in M[u]:
  v-=1
  if d[v]<0:d[v]=d[u]+1;q.put(v) q.qsize()>0 q.qsize() q.qsize q qsize 0 u=q.get() u q.get() q.get q get for v in M[u]:
  v-=1
  if d[v]<0:d[v]=d[u]+1;q.put(v) v M[u] M u v-=1 v 1 if d[v]<0:d[v]=d[u]+1;q.put( d[v]<0 d[v] d v 0 for i in range(N):print(i+1,d[i]) i range(N) range N M=[list(map(int,e.split()[2:]))for e in sys.stdin] [list(map(int,e.split()[2:]))for e in sys.stdin] M q=queue.Queue() queue.Queue() q u=q.get() q.get() u v-=1 1 v N=int(input()) int(input()) N d=[-1]*N [-1]*N d
import queue,sys
N=int(input())
M=[list(map(int,e.split()[2:]))for e in sys.stdin]
q=queue.Queue();q.put(0)
d=[-1]*N;d[0]=0
while q.qsize()>0:
 u=q.get()
 for v in M[u]:
  v-=1
  if d[v]<0:d[v]=d[u]+1;q.put(v)
for i in range(N):print(i+1,d[i])
