N=int(input())
M=[input().split()[2:]for _ in[0]*N]
q=[0]
d=[-1]*N;d[0]=0
while q:
 u=q.pop(0)
 for v in M[u]:
  v=int(v)-1
  if d[v]<0:d[v]=d[u]+1;q+=[v]
for i in range(N):print(i+1,d[i]) N=int(input()) N int(input()) int input() input input().split()[2:]for _ in[0]*N for _ in[0]*N _ [0]*N [0] 0 N for _ in[0]*N input().split()[2:] ().split() ().split () input split 2: 2 M=[input().split()[2:]for _ in[0]*N] M [input().split()[2:]for _ in[0]*N] q=[0] q [0] 0 d=[-1]*N d [-1]*N [-1] -1 N d[0]=0 d[0] d 0 0 while q:
 u=q.pop(0)
 for v in M[u]:
  v=int(v)-1
  if d[v]<0:d[v]=d[u]+1;q+=[v] q u=q.pop(0) u q.pop(0) q.pop q pop 0 for v in M[u]:
  v=int(v)-1
  if d[v]<0:d[v]=d[u]+1;q+=[v] v M[u] M u v=int(v)-1 v int(v)-1 int(v) int v 1 if d[v]<0:d[v]=d[u]+1;q+=[ d[v]<0 d[v] d v 0 for i in range(N):print(i+1,d[i]) i range(N) range N N=int(input()) int(input()) N M=[input().split()[2:]for _ in[0]*N] [input().split()[2:]for _ in[0]*N] M d=[-1]*N [-1]*N d v=int(v)-1 int(v)-1 v q=[0] [0] q u=q.pop(0) q.pop(0) u
N=int(input())
M=[input().split()[2:]for _ in[0]*N]
q=[0]
d=[-1]*N;d[0]=0
while q:
 u=q.pop(0)
 for v in M[u]:
  v=int(v)-1
  if d[v]<0:d[v]=d[u]+1;q+=[v]
for i in range(N):print(i+1,d[i])
