from collections import deque import bisect n,m = map(int,input().split()) pq = [[] for i in range(n)] for i in range(m): p,q = map(int,input().split()) p -= 1 q -= 1 pq[p].append(q) pq[q].append(p) q = int(input()) a = [int(input())-1 for i in range(q)] ans = [] rui = [2**i for i in range(20)] #idx = bisect.bisect_left(cnt,8) #print(cnt) #print(idx) for i in range(q): chk = [0]*n chk[a[i]] = 1 d = deque() d.append([a[i],0]) mcnt = 0 while len(d) > 0: tmp,cnt = d.popleft() for j in pq[tmp]: if chk[j] == 0: chk[j] = 1 d.append([j,cnt+1]) mcnt = cnt+1 if mcnt == 0: ans.append([0,0]) else: idx = bisect.bisect_left(rui,mcnt) #ans.append([sum(chk)-1,(mcnt+1)//2]) ans.append([sum(chk)-1,idx]) for i in range(len(ans)): print(*ans[i])