n,m=map(int, input().split()) pq = [list(map(int, input().split())) for i in range(m)] Q=int(input()) a = [int(input()) for i in range(Q)] b=[[] for i in range(n+1)] for i in pq: p=i[0] q=i[1] b[p].append(q) b[q].append(p) for i in a: if(b[i]==[]): print(0,0) continue que=[i] check=[0 for i in range(n+1)] check[i]=1 fri=0 dif=-1 while len(que)>0: tmpl=que.copy() que=[] for j in tmpl: for k in b[j]: if(check[k]==0): que.append(k) check[k]=1 fri+=1 dif+=1 if(dif==1): day=0 else: day=-(-dif//2) print(fri,day)